标签<unknown> </unknown>的Android InflateException

时间:2011-10-17 12:02:37

标签: android android-inflate

我的应用程序适用于我们测试过的大多数设备,但在少数20个测试用户中,其中2个出现了一个非常奇怪的错误:

10-17 08:56:56.840 24805 24846 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #52: Error inflating class <unknown>

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at android.view.LayoutInflater.createView(LayoutInflater.java:513)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at com.nzn.baixaki.AppsActivity$LoadCategoriesTask.doInBackground(AppsActivity.java:71)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at com.nzn.baixaki.AppsActivity$LoadCategoriesTask.doInBackground(AppsActivity.java:1)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at android.os.AsyncTask$2.call(AsyncTask.java:185)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    ... 4 more

10-17 08:56:56.840 24805 24846 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at android.widget.ListView.<init>(ListView.java:153)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at java.lang.reflect.Constructor.constructNative(Native Method)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at java.lang.reflect.Constructor.newInstance(Constructor.java:446)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    at android.view.LayoutInflater.createView(LayoutInflater.java:500)

10-17 08:56:56.840 24805 24846 E AndroidRuntime:    ... 14 more

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <!-- LINHA AZUL // -->
    <LinearLayout
        android:background="@drawable/bg_filters"
        android:id="@+id/category_header"
        android:visibility="gone"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:orientation="vertical">
        <!-- LINHA DE CIMA // -->
        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dip"
            android:paddingRight="10dip"
            android:paddingLeft="10dip"
            android:paddingTop="10dip">
            <!-- LABEL 'CATEGORIA' -->
            <TextView
                android:gravity="center_vertical"
                android:layout_height="fill_parent"
                android:layout_width="wrap_content"
                android:textColor="@color/bxkBlue"
                android:text="@string/category_title_call"
                android:textSize="14dip"
                android:layout_marginRight="5dip">
            </TextView>
            <!-- NOME DA CATEGORIA -->
            <TextView
                android:gravity="center_vertical"
                android:layout_height="fill_parent"
                android:layout_width="wrap_content"
                android:textColor="@color/bxkBlue"
                android:text="Nome da categoria"
                android:textSize="14dip"
                android:textStyle="bold"
                android:id="@+id/category_name">
            </TextView>
        </LinearLayout>
        <View
            android:layout_height="1dip"
            android:layout_width="fill_parent"
            android:background="#e5e5e5"/>
    </LinearLayout>
    <ListView
        android:listSelector="@drawable/bg_list_selector"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/apps_list_view"></ListView>
</LinearLayout>

XML上的第52行是底部的ListView。可能会发生什么?

我真的不知道如何解决这个错误。

编辑:

阅读链接后,我仍然不知道,但这个堆栈跟踪可能有所帮助:

10-17 09:28:48.919 25897 25983 W System.err: Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

10-17 09:28:48.929 25897 25983 W System.err:    at android.os.Handler.<init>(Handler.java:121)

10-17 09:28:48.929 25897 25983 W System.err:    at android.view.GestureDetector$GestureHandler.<init>(GestureDetector.java:250)

10-17 09:28:48.929 25897 25983 W System.err:    at android.view.GestureDetector.<init>(GestureDetector.java:370)

10-17 09:28:48.929 25897 25983 W System.err:    at android.view.GestureDetector.<init>(GestureDetector.java:347)

10-17 09:28:48.929 25897 25983 W System.err:    at android.view.GestureDetector.<init>(GestureDetector.java:331)

10-17 09:28:48.929 25897 25983 W System.err:    at android.widget.AbsListView.initAbsListView(AbsListView.java:585)

10-17 09:28:48.929 25897 25983 W System.err:    at android.widget.AbsListView.<init>(AbsListView.java:544)

10-17 09:28:48.929 25897 25983 W System.err:    at android.widget.ListView.<init>(ListView.java:157)

10-17 09:28:48.929 25897 25983 W System.err:    ... 18 more

让我烦恼的是,几乎所有代码都是“内部”而不是我的......

3 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

在查看原因后我发现了问题。

基本上我在AsyncTask中对视图进行了膨胀,但是在doInBackground()方法上这样做了,这显然适用于大多数设备,但不是全部。

我将膨胀部分移动到onPostExecute()并解决了问题。

答案 2 :(得分:0)

修复错误:

在清单中:

<application
        android:largeHeap="true"

在.xml文件中,您必须删除以下代码:

android:src="@drawable..
android:background="@drawable...

因为错误是内存不足错误。这对我有好处