Android:如何追踪 InflateException 的来源? [英] Android: How to track down the origin of a InflateException?

查看:29
本文介绍了Android:如何追踪 InflateException 的来源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在启动我的应用程序时,我在 Logcat 中收到以下警告:

While starting my application I get the following warning in Logcat:

04-09 10:28:17.830: WARN/WindowManager(52): Exception when adding starting window
04-09 10:28:17.830: WARN/WindowManager(52): android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
04-09 10:28:17.830: WARN/WindowManager(52):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
04-09 10:28:17.830: WARN/WindowManager(52):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-09 10:28:17.830: WARN/WindowManager(52):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-09 10:28:17.830: WARN/WindowManager(52):     at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
04-09 10:28:17.830: WARN/WindowManager(52):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-09 10:28:17.830: WARN/WindowManager(52):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-09 10:28:17.830: WARN/WindowManager(52):     at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2153)
04-09 10:28:17.830: WARN/WindowManager(52):     at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2207)
04-09 10:28:17.830: WARN/WindowManager(52):     at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1395)
04-09 10:28:17.830: WARN/WindowManager(52):     at com.android.internal.policy.impl.PhoneWindowManager.addStartingWindow(PhoneWindowManager.java:818)
04-09 10:28:17.830: WARN/WindowManager(52):     at com.android.server.WindowManagerService$H.handleMessage(WindowManagerService.java:8794)
04-09 10:28:17.830: WARN/WindowManager(52):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 10:28:17.830: WARN/WindowManager(52):     at android.os.Looper.loop(Looper.java:123)
04-09 10:28:17.830: WARN/WindowManager(52):     at com.android.server.WindowManagerService$WMThread.run(WindowManagerService.java:531)
04-09 10:28:17.830: WARN/WindowManager(52): Caused by: java.lang.reflect.InvocationTargetException
04-09 10:28:17.830: WARN/WindowManager(52):     at android.widget.FrameLayout.<init>(FrameLayout.java:79)
04-09 10:28:17.830: WARN/WindowManager(52):     at java.lang.reflect.Constructor.constructNative(Native Method)
04-09 10:28:17.830: WARN/WindowManager(52):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
04-09 10:28:17.830: WARN/WindowManager(52):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
04-09 10:28:17.830: WARN/WindowManager(52):     ... 13 more
04-09 10:28:17.830: WARN/WindowManager(52): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x1010059 a=-1}
04-09 10:28:17.830: WARN/WindowManager(52):     at android.content.res.Resources.loadDrawable(Resources.java:1677)
04-09 10:28:17.830: WARN/WindowManager(52):     at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
04-09 10:28:17.830: WARN/WindowManager(52):     at android.widget.FrameLayout.<init>(FrameLayout.java:91)
04-09 10:28:17.830: WARN/WindowManager(52):     ... 17 more

我的应用程序从以下闪屏开始:

My Application starts with the following splash screen:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:windowBackground="@color/white" android:background="@color/white"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:foregroundGravity="center">

    <ImageView android:id="@+id/ImageView01"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:adjustViewBounds="true" android:scaleType="centerInside"
        android:src="@drawable/splash" android:layout_gravity="center" />


</ScrollView>

启动画面是显示在启动画面中的图像.我有这四个文件夹用于在我的应用程序中存储可绘制对象:

Splash is the image that is shown in the splash screen. I have those four folders with for storing drawables in my app:

/res/drawable-hdpi
/res/drawable-ldpi
/res/drawable-mdpi
/res/drawable-nodpi

/res/drawable-hdpi
/res/drawable-ldpi
/res/drawable-mdpi
/res/drawable-nodpi

启动图像在前三个中有自己的版本并且显示正确.从 ImageView 中移除 src 属性会移除图像,但不会移除异常.

the splash image has its own version in the first three of them and is displayed properly. Removing the src property from the ImageView removes the image but not the exception.

我有点不知道在哪里寻找异常的原因.我什至不知道这是否真的是这个布局文件等中的问题.

I'm a little bit lost with where to look for the cause of the exception. I even don't know if this is really an issue in this layout file etc.

您将如何查找此警告的原因?

How would you go about finding the cause for this warning?

推荐答案

我遇到了同样的错误.唯一有意义的 xml 第 24 行是我的应用程序清单,它恰好是应用程序的结束标记.我将其追溯到我为应用程序添加的自定义主题——我没有定义样式的父级.我需要做的就是将 parent="android:Theme" 添加到我的样式中,然后我的错误就消失了.

I had the same exact error. The only xml line 24 that made any sense was my application manifest which happened to be the closing tag for application. I traced it down to my custom theme I was adding for the app -- I was not defining the parent of the style. All I needed to do was add parent="android:Theme" to my style and my error went away.

<style name="MyTheme" parent="android:Theme">
...
</style>

这篇关于Android:如何追踪 InflateException 的来源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆