Binary XML file line #2: Error inflating class android.widget.AbsoluteLayout

        自定义一个View,并在layout文件中进行部署,执行程序报以下错误:

E/AndroidRuntime( 1292): FATAL EXCEPTION: main
E/AndroidRuntime( 1292): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.raycommtech/com.raycommtech.HomecloudActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.AbsoluteLayout
E/AndroidRuntime( 1292): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
E/AndroidRuntime( 1292): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/AndroidRuntime( 1292): 	at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 1292): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
E/AndroidRuntime( 1292): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1292): 	at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 1292): 	at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 1292): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1292): 	at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1292): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 1292): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 1292): 	at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1292): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.AbsoluteLayout
E/AndroidRuntime( 1292): 	at android.view.LayoutInflater.createView(LayoutInflater.java:518)
E/AndroidRuntime( 1292): 	at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime( 1292): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
E/AndroidRuntime( 1292): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
E/AndroidRuntime( 1292): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime( 1292): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime( 1292): 	at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
E/AndroidRuntime( 1292): 	at android.app.Activity.setContentView(Activity.java:1657)
E/AndroidRuntime( 1292): 	at com.raycommtech.HomecloudActivity.onCreate(HomecloudActivity.java:92)
E/AndroidRuntime( 1292): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 1292): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
E/AndroidRuntime( 1292): 	... 11 more
E/AndroidRuntime( 1292): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 1292): 	at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 1292): 	at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
E/AndroidRuntime( 1292): 	at android.view.LayoutInflater.createView(LayoutInflater.java:505)
E/AndroidRuntime( 1292): 	... 21 more
E/AndroidRuntime( 1292): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f020020 a=-1 r=0x7f020020}
E/AndroidRuntime( 1292): 	at android.content.res.Resources.loadDrawable(Resources.java:1681)
E/AndroidRuntime( 1292): 	at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime( 1292): 	at android.view.View.<init>(View.java:1951)
E/AndroidRuntime( 1292): 	at android.view.View.<init>(View.java:1899)
E/AndroidRuntime( 1292): 	at android.view.ViewGroup.<init>(ViewGroup.java:286)
E/AndroidRuntime( 1292): 	at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:47)
E/AndroidRuntime( 1292): 	... 24 more
开始以为是自定义的View重载的方法有问题,网上也查了很多关于自定义View方面引发的错误,还是木有得到解决。

       仔细看看错误,就是没有找到资源文件,看看res/下面的资源文件,全放在drawable-mdpi/目录下,突然灵光一现,怀疑寻找的位置资源文件不存在,于是将drawable-mdpi/下的资源文件拷贝一份到drawable-ldpi/目录下,还是报上面的错误,再拷贝一份到drawable-hdpi/目录下,问题解决。

       还有另外一种解决方法是在res/下建一目录drawable/,将drawable-mdpi/下所有的资源文件都拷贝到drawable/下即可




你可能感兴趣的:(xml,exception,File,layout,Class,Path)