今天遇到一个很无语的问题,竟然是9Patch图片上多加了光晕效果。
因为需要自定义Button,所以请用了9Patch图片,而且图片上面还有一点光晕效果,同样也被拉伸了,在2.2的系统上面正常能跑,2.1上面就出问题,报了如下的错:
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): java.lang.RuntimeException: Unable to start activity ComponentInfo{*/*}: android.view.InflateException: Binary XML file line #25: Error inflating class
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2553)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2569)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.app.ActivityThread.access$2200(ActivityThread.java:125)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1914)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.os.Handler.dispatchMessage(Handler.java:99)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.os.Looper.loop(Looper.java:123)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.app.ActivityThread.main(ActivityThread.java:4420)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at java.lang.reflect.Method.invokeNative(Native Method)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at java.lang.reflect.Method.invoke(Method.java:521)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:682)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at dalvik.system.NativeStart.main(Native Method)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:203)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.app.Activity.setContentView(Activity.java:1622)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at *.onCreate(LocalBooksActivity.java:28)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2516)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): ... 11 more
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): Caused by: java.lang.reflect.InvocationTargetException
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.widget.Button.(Button.java:65)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at java.lang.reflect.Constructor.constructNative(Native Method)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): ... 24 more
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): Caused by: java.lang.StackOverflowError
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.content.res.StringBlock.get(StringBlock.java:69)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.content.res.AssetManager.getResourceValue(AssetManager.java:186)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.content.res.Resources.getValue(Resources.java:933)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.content.res.Resources.getDrawable(Resources.java:597)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:160)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.content.res.Resources.loadDrawable(Resources.java:1771)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.content.res.Resources.getDrawable(Resources.java:598)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:160)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.content.res.Resources.loadDrawable(Resources.java:1771)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.content.res.Resources.getDrawable(Resources.java:598)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:160)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.content.res.Resources.loadDrawable(Resources.java:1771)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.content.res.Resources.getDrawable(Resources.java:598)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:160)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
11-03 17:29:12.411: ERROR/AndroidRuntime(11390): at android.graphics.d
错误给出了是哪儿出错,很明显是布局文件,然后还告诉了哪一行,也就是在哪个组件中定义属性出错,是Button。最后想不明白,是不是用了2.1不支持的属性,感觉不会,因为2.1不支持,最多也就不认,不至于会出错吧,反正这种情况是没遇到过。最后找到竟然是android:background属性定义的有错,不会呀,一直都是这么处理按钮图片的,换一组没有问题的自定义按钮的图片,一切OK,很无语,只能说明图片有问题,哪张图片有问题?一个个的试,最后就还真找出是那张图片的问题,倒底是图片什么问题?格式?大小?最后更无语的是竟然是图片上面多了点光晕效果引起的问题,还是2.1上面出现的问题,解决这个问题的还是直觉,感觉那个光晕不爽,去掉就OK了。估计是android的9Patch工具做的还不够好。折腾一个小时终于搞定了。