Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I've been looking into this issue for hours and similar errors that had solutions didn't do the trick.

I'm reusing this XML file for multiple ListViews in different activities (which I'm assuming has something to do with it) but I do not see why it would break. The XML file represents the individual items in the ListView.

Here's the XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="5dp" >

    <LinearLayout
        android:id="@+id/post"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="?attr/postBackground"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/postTop"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:padding="8dp" >

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                    <!-- Title -->

                    <TextView
                        android:id="@+id/title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:fontFamily="sans-serif-light"
                        android:textColor="?attr/postTitle"
                        android:textSize="16sp"
                        android:textStyle="bold" />

                    <!-- subreddit + domain -->

                    <TextView
                        android:id="@+id/subredditDomainVotes"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:fontFamily="sans-serif"
                        android:gravity="left"
                        android:textColor="#828282"
                        android:textSize="13sp" />

                    <TextView
                        android:id="@+id/date"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:fontFamily="sans-serif"
                        android:gravity="left"
                        android:textColor="#828282"
                        android:textSize="13sp" />
                </LinearLayout>

            </LinearLayout>

            <ImageView
                android:id="@+id/imagePreview"
                android:layout_width="fill_parent"
                android:layout_height="200dp"
                android:adjustViewBounds="false"
                android:background="?attr/postPreviewBground"
                android:contentDescription="@string/empty"
                android:scaleType="centerCrop" />

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="?attr/postBottom"
                android:padding="8dp" >

                <!-- Author -->

                <TextView
                    android:id="@+id/author"
                    style="?attr/postButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:textSize="12sp" />

                <!-- Comments -->

                <TextView
                    android:id="@+id/comments"
                    style="?attr/postButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:textSize="12sp" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

</FrameLayout>

And here's the Java (error occurs on convertView = (FrameLayout) FrameLayout.inflate(mContext, R.layout.column_post, null);) :

@Override
public View getView(int position, View convertView, ViewGroup parent) {

JSONObject thePost = null;
String kind = null;
try {
    thePost = mPosts.getJSONObject(position);
    kind = thePost.getString("kind");
} catch (Exception e) {
    System.out.println("errreoroer");
}

if (null == convertView) {

    LayoutInflater inflater = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    convertView = new FrameLayout(mContext);

    if (Switches.getInMailView()) {

        convertView = (RelativeLayout) inflater.inflate(
                R.layout.mail_post, parent, false);

        mailHolder = new MailHolder();
        mailHolder.authorView = (TextView) convertView
                .findViewById(R.id.author);
        mailHolder.dateView = (TextView) convertView
                .findViewById(R.id.date);
        mailHolder.subjectView = (TextView) convertView
                .findViewById(R.id.subject);

    } else {

        if (kind.equals("t3")) {
                  //ERROR HAPPENS RIGHT HERE
            convertView = (FrameLayout) FrameLayout.inflate(mContext, R.layout.column_post, null);

            holder = new PostHolder();
            // grab the post view objects
            holder.postTitleView = (TextView) convertView
                    .findViewById(R.id.title);
            holder.dateView = (TextView) convertView
                    .findViewById(R.id.date);
            holder.authorView = (TextView) convertView
                    .findViewById(R.id.author);
            holder.commentsView = (TextView) convertView
                    .findViewById(R.id.comments);
            holder.subredditDomainVotesView = (TextView) convertView
                    .findViewById(R.id.subredditDomainVotes);
            holder.imagePreviewView = (ImageView) convertView
                    .findViewById(R.id.imagePreview);
            holder.postTopView = (LinearLayout) convertView
                    .findViewById(R.id.postTop);

            convertView.setTag(holder);

        }

    }

} else {

    if (Switches.getInMailView())
        mailHolder = (MailHolder) convertView.getTag();
    else {

        if (kind.equals("t3"))
            holder = (PostHolder) convertView.getTag();

    }

}

try {

    if (Switches.getInMailView())
        return buildMailPostItem((RelativeLayout) convertView,
                thePost.getJSONObject("data"), kind);
    else {
        if (kind.equals("t3"))
            return buildGenericPostItem((FrameLayout) convertView,
                    thePost.getJSONObject("data"), kind, position);
    }

} catch (JSONException e) {

    return null;
}

return convertView;

}

Stacktrace

11-26 18:23:09.492: E/AndroidRuntime(4616): FATAL EXCEPTION: main
11-26 18:23:09.492: E/AndroidRuntime(4616): Process: com.reditr.app, PID: 4616
11-26 18:23:09.492: E/AndroidRuntime(4616): android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at com.reditr.adapters.PostAdapter.getView(PostAdapter.java:145)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.AbsListView.obtainView(AbsListView.java:2263)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.ListView.makeAndAddView(ListView.java:1790)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.ListView.fillDown(ListView.java:691)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.ListView.fillFromTop(ListView.java:752)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.ListView.layoutChildren(ListView.java:1630)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.AbsListView.onLayout(AbsListView.java:2091)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.View.layout(View.java:14785)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.View.layout(View.java:14785)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.View.layout(View.java:14785)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.View.layout(View.java:14785)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1585)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.View.layout(View.java:14785)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1660)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.View.layout(View.java:14785)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.View.layout(View.java:14785)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.View.layout(View.java:14785)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.View.layout(View.java:14785)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1985)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1742)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5582)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.Choreographer.doFrame(Choreographer.java:532)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.os.Handler.handleCallback(Handler.java:733)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.os.Handler.dispatchMessage(Handler.java:95)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.os.Looper.loop(Looper.java:137)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at android.app.ActivityThread.main(ActivityThread.java:4998)
11-26 18:23:09.492: E/AndroidRuntime(4616):     at java.lang.refl

Thanks in advance.

share|improve this question
1  
can you post your stracktrace ? – kiruwka Nov 26 '13 at 21:58
    
updated with stacktrace – vivatus Nov 26 '13 at 22:05
1  
well, first thing : try removing line android:background="?attr/postBackground" and see if you have different log (could crash at another line, or could work). – kiruwka Nov 26 '13 at 22:31
4  
and you sure both of your activities use the same theme ? – kiruwka Nov 26 '13 at 22:37
5  
Well, glad it helped. I can put my comment as an answer for you to accept if you like, so you can convert your 10000 points to 15. Otherwise just put the solution and accept an answer so it could be helpful for others – kiruwka Nov 26 '13 at 22:43
up vote 7 down vote accepted

Thanks to @kiruwka, the problem is fixed!

The issue was that I needed to make sure that I was using the same theme across activities.

share|improve this answer

I would use the inflator you grabbed from your context rather than the static method from FrameLayout, just to keep the code clear. FrameLayout's inherited inflate() method is just a wrapper around calling Context.getSystemService() then calling inflate. Try changing it to this:

        convertView =
            (FrameLayout)inflater.inflate(mContext,
                                          R.layout.column_post,
                                          parent,
                                          false);

I suspect the crash you are seeing is because you are passing null for the parent and the the default inflate() variant will attempt to attach the new child view you are creating to the parent (which you don't want to do.)

share|improve this answer
    
I just tried that out but I still get the same error. – vivatus Nov 26 '13 at 22:24
    
What is the name of your XML file? I know you said you are re-using it for multiple things, is it the same content just re-named? Is this XML file at res/layout/column_post.xml in your tree? – Larry Schiefer Nov 26 '13 at 22:36
    
Yeah, the xml file is just located in res/layout/column_post.xml. It only crashes when I use it in a separate activity. It works fine if I reuse the same XML file within the same activity. – vivatus Nov 26 '13 at 22:39
    
Just fixed the issue, @kiruwka said to make sure that the activities had the same theme. It turned out they didn't, and boom it worked! – vivatus Nov 26 '13 at 22:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.