Android的:如何追查InflateException的由来?由来、Android、InflateException

2023-09-12 02:23:49 作者:软妹小仙女

虽然开始我的应用程序,我得到的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 /绘制,华电国际 / RES /绘制,LDPI / RES /绘制,MDPI / RES /绘制-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,使得任何意义是它正好是对应用程序的结束标记我的应用程序清单。我跟踪下来到我的自定义主题,我增加了对应用程序 - 我没有定义风格的父。所有我需要做的是增加父母=安卓主题我的风格,我的错误走了

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>