由于Resource $ NotFoundException,我的活动随机崩溃,并且它总是由于我的一个自定义按钮的状态选择器文件。崩溃是完全随机的,我将在没有崩溃的情况下多次浏览整个应用程序,然后第n次进入一个Activity,然后它将抛出异常。
堆栈追踪:
07-12 11:12:18.469 2086 2086 D AndroidRuntime: Shutting down VM
07-12 11:12:18.469 2086 2086 W dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x400208b0)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: FATAL EXCEPTION: main
07-12 11:12:18.508 2086 2086 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appname.droid/com.appname.droid.send.ConfirmActivity}: android.view.InflateException: Binary XML file line #123: Error inflating class <unknown>
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2737)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.app.ActivityThread.access$2500(ActivityThread.java:129)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.os.Looper.loop(Looper.java:143)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:4701)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:521)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #123: Error inflating class <unknown>
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:513)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:203)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.app.Activity.setContentView(Activity.java:1647)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at com.appname.droid.send.ConfirmActivity.onCreate(ConfirmActivity.java:40)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: ... 11 more
07-12 11:12:18.508 2086 2086 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.widget.Button.<init>(Button.java:65)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at java.lang.reflect.Constructor.constructNative(Native Method)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:500)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: ... 24 more
07-12 11:12:18.508 2086 2086 E AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: File res/drawable/btn_green.xml from drawable resource ID #0x7f020020
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.content.res.Resources.loadDrawable(Resources.java:1725)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.view.View.<init>(View.java:1885)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.widget.TextView.<init>(TextView.java:369)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.widget.Button.<init>(Button.java:69)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: ... 28 more
07-12 11:12:18.508 2086 2086 E AndroidRuntime: Caused by: java.lang.NullPointerException
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.graphics.drawable.DrawableContainer$DrawableContainerState.addChild(DrawableContainer.java:349)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.graphics.drawable.StateListDrawable$StateListState.addStateSet(StateListDrawable.java:265)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:796)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.graphics.drawable.Drawable.createFromXml(Drawable.java:737)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: at android.content.res.Resources.loadDrawable(Resources.java:1722)
07-12 11:12:18.508 2086 2086 E AndroidRuntime: ... 32 more
07-12 11:12:18.515 1235 1235 W ActivityManager: Force finishing activity com.appname.droid/.send.ConfirmActivity
ConfirmActivity中的第40行是一段代码:
setContentView(R.layout.confirm);
这是res / drawable / btn_green.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="@drawable/green_large_btn_pressed" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/green_large_btn_pressed" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/green_large_btn" />
<item
android:state_enabled="true"
android:drawable="@drawable/green_large_btn" />
</selector>
此异常发生在整个应用程序中,它始终是我的按钮之一。我的btn_gray和btn_orange也会发生同样的事情。
color_large_btn.png和color_large_btn_pressed.png都适用于所有颜色。
Android版: 目前在运行Android 2.2的Droid2上 摩托罗拉Blur也运行Android 2.1 似乎没有发生在运行Android 2.3的HTC Evo上
答案 0 :(得分:2)
此问题基本上是内存不足的情况。在try-catch块中包装我的xml文件后,我能够通过这个初始错误,无法加载文件/找到它们。产生的行为是带有图像的活动,直到最后抛出实际的内存不足异常。
修正?找到并删除了大量泄漏,并缩小了几个图像文件的大小。