歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Android2.1加載9Patch圖片運行後報錯

今天遇到一個很無語的問題,竟然是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 <unknown>
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 <unknown>
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.<init>(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工具做的還不夠好。折騰一個小時終於搞定了。

Copyright © Linux教程網 All Rights Reserved