java – android.view.InflateException:二进制XML文件行#9:错误类膨胀

前端之家收集整理的这篇文章主要介绍了java – android.view.InflateException:二进制XML文件行#9:错误类膨胀前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在研究这个问题几个小时和类似的错误,解决方案没有做到这一点.

我在不同的活动中重复使用这个XML文件用于多个ListView(我假设它与它有关)但我不明白为什么它会破坏. XML文件表示ListView中的各个项目.

这是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>

这是Java(在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,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,kind,position);
    }

} catch (JSONException e) {

    return null;
}

return convertView;

}

堆栈跟踪

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

提前致谢.

解决方法

感谢@kiruwka,问题得到解决

问题是我需要确保我在各种活动中使用相同的主题.

原文链接:https://www.f2er.com/java/120876.html

猜你在找的Java相关文章