android.view.InflateException: Binary XML file line #33: Error inflating class

在调试的时候,发现在有些机器上出现下面的错误。


09-29 16:00:58.979: E/AndroidRuntime(29450): FATAL EXCEPTION: main

09-29 16:00:58.979: E/AndroidRuntime(29450): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.mcancersurvivor/com.project.mcancersurvivor.fooddiary.FoodDiaryActivity}: android.view.InflateException: Binary XML file line #33: Error inflating class
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.app.ActivityThread.access$600(ActivityThread.java:150)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1266)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.os.Looper.loop(Looper.java:137)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.app.ActivityThread.main(ActivityThread.java:5256)
09-29 16:00:58.979: E/AndroidRuntime(29450): at java.lang.reflect.Method.invokeNative(Native Method)
09-29 16:00:58.979: E/AndroidRuntime(29450): at java.lang.reflect.Method.invoke(Method.java:525)
09-29 16:00:58.979: E/AndroidRuntime(29450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:743)
09-29 16:00:58.979: E/AndroidRuntime(29450): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:559)
09-29 16:00:58.979: E/AndroidRuntime(29450): at dalvik.system.NativeStart.main(Native Method)
09-29 16:00:58.979: E/AndroidRuntime(29450): Caused by: android.view.InflateException: Binary XML file line #33: Error inflating class
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
09-29 16:00:58.979: E/AndroidRuntime(29450): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-29 16:00:58.979: E/AndroidRuntime(29450): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.app.Activity.setContentView(Activity.java:1895)
09-29 16:00:58.979: E/AndroidRuntime(29450): at com.project.mcancersurvivor.fooddiary.FoodDiaryActivity.onCreate(FoodDiaryActivity.java:86)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.app.Activity.performCreate(Activity.java:5133)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2290)
09-29 16:00:58.979: E/AndroidRuntime(29450): ... 11 more
09-29 16:00:58.979: E/AndroidRuntime(29450): Caused by: java.lang.reflect.InvocationTargetException
09-29 16:00:58.979: E/AndroidRuntime(29450): at java.lang.reflect.Constructor.constructNative(Native Method)
09-29 16:00:58.979: E/AndroidRuntime(29450): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
09-29 16:00:58.979: E/AndroidRuntime(29450): ... 25 more
09-29 16:00:58.979: E/AndroidRuntime(29450): Caused by: java.lang.StackOverflowError
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.content.res.Resources.getValue(Resources.java:1114)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.content.res.Resources.getDrawable(Resources.java:693)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:901)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.content.res.Resources.loadDrawable(Resources.java:2114)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.content.res.Resources.getDrawable(Resources.java:695)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:901)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.content.res.Resources.loadDrawable(Resources.java:2114)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.content.res.Resources.getDrawable(Resources.java:695)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:901)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.content.res.Resources.loadDrawable(Resources.java:2114)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.content.res.Resources.getDrawable(Resources.java:695)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:901)
09-29 16:00:58.979: E/AndroidRuntime(29450): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)

09-29 16:00:58.979: E/AndroidRuntime(29450): at android.content.res.Resources.loadDraw


最终定位问题的位置为:


只要有
android:src="@drawable/right_arrow"

就会出现问题。问题原因是java.lang.StackOverflowError

后来发现

right_arrow.xml 中引用了相同名字的资源文件right_arrow.png,所以导致嵌套调用,资源溢出。将.png名字改为与.xml不同,问题解决。



    
    


你可能感兴趣的:(android,开发学习)