标签的 Android InflateException

发布于 12-10 11:35 字数 6120 浏览 0 评论 0原文

我有一个应用程序可以在我们测试过的大多数设备上运行,但在少数 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

困扰我的是几乎所有代码都是“内部”而不是我的......

I have an app that works on most devices we've tested, but in the few 20 beta users 2 of them get a very weird error:

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

And here is the 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>

Line 52 on the XML is the ListView at the bottom. What could be happening?

I really have no idea of how to fix this error.

EDIT:

After reading a link, I've still got no idea, but this stacktrace might help:

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

What is bugging me is that pretty much all the code is "internal" and not mine...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苯莒2024-12-17 11:35:42

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

基本上,我是在 AsyncTask 中膨胀视图,但在 doInBackground() 方法上执行此操作,该方法显然适用于大多数设备,但不适用于所有设备。

我将 inflate 部分移至 onPostExecute() 并解决了问题。

I've found out the problem after looking at the cause.

Basically I was inflating a view in a AsyncTask but was doing that on the doInBackground() method, which apparently works on most devices, but not all of them.

I moved the inflate part to the onPostExecute() and it fixed the problem.

遇见了你2024-12-17 11:35:42

要修复该错误:

在清单中:

<application
        android:largeHeap="true"

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

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

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

To fix the error:

In Manifest:

<application
        android:largeHeap="true"

In .xml file, you must remove the below code:

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

Because the error is out of memory error. It is good for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文