Android的自定义按钮状态选择XML文件,造成资源$ NotFoundException自定义、按钮、状态、文件

由网友(良辰.)分享简介:我的活动随机崩溃,由于资源$ NotFoundException它总是因为我的一个自定义按钮的状态选择文件。而崩溃是完全随机的,我多次去完成整个程序没有崩溃,然后去一个活动的第n次,然后它会抛出异常。My Activities are randomly crashing due to Resource$NotFoun...

我的活动随机崩溃,由于资源$ NotFoundException它总是因为我的一个自定义按钮的状态选择文件。而崩溃是完全随机的,我多次去完成整个程序没有崩溃,然后去一个活动的第n次,然后它会抛出异常。

My Activities are randomly crashing due to Resource$NotFoundException and it's always due to one of my custom button's state selector files. And the crashes are completely random, I'll go through the entire app multiple times with no crashes, and then go to an Activity for the nth time, and then it'll throw the exception.

堆栈跟踪:

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是一张code:

And line 40 in ConfirmActivity is the piece of code:

setContentView(R.layout.confirm);

这里是RES /绘制/ btn_green.xml

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

This exception occurs throughout the app and it's always one of my buttons. The same thing happens with my btn_gray and btn_orange.

color_large_btn.png和color_large_btn_ pressed.png都是present所有颜色。

color_large_btn.png and color_large_btn_pressed.png are all present for all colors.

Android版本: 目前上的Droid2运行Android 2.2 同样发生在摩托罗拉模糊运行的是Android 2.1 似乎并没有发生在宏达电Evo运行Android 2.3

Android Version: Currently on a Droid2 running Android 2.2 Also happens on a Motorola Blur running Android 2.1 Doesn't seem to happen on HTC Evo running Android 2.3

推荐答案

这个问题本质上是一个彻头彻尾的内存场景。结束了我的XML文件中膨胀的try-catch块后,我能获得通过不能够加载文件/找到他们的这个初始误差。由此产生的行为与图像活动只是普通的失踪,直到最后一个实际的内存不够的异常被抛出。

This issue is essentially an out of memory scenario. After wrapping up my inflating of xml files in try-catch blocks, I was able to get passed this initial error of not being able to load in files/ find them. The resulting behavior is Activities with images just plain missing until finally an actual out of memory exception is thrown.

解决?找到并删除大量泄漏和减小尺寸一对夫妇的图像文件。

Fix? Found and removed numerous leaks and down sized a couple image files.

阅读全文

相关推荐

最新文章