有时候开发中,明明有布局文件,而且代码中只加载布局文件,却提示资源找不到,报如下错误,找了又找,布局文件明明存在啊,这TM什么莫名其妙的错误?!
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shangche.tachograph/com.shangche.tachograph.facee.Test}: android.content.res.Resources$NotFoundException: Resource ID #0x7f04003e
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2581)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2656)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1512)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5691)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f04003e
at android.content.res.Resources.getValue(Resources.java:1483)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2951)
at android.content.res.Resources.getLayout(Resources.java:1257)
at android.view.LayoutInflater.inflate(LayoutInflater.java:412)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:430)
at android.app.Activity.setContentView(Activity.java:2217)
at com.shangche.tachograph.facee.Test.onCreate(Test.java:19)
at android.app.Activity.performCreate(Activity.java:6142)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1115)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2528)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2656)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1512)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5691)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
仔细检查发现,原来配置文件中指定了竖屏,而布局文件是放在横屏文件夹下,而指定了竖屏就只会去竖屏文件夹找相应的资源文件,所以就会出现找不到的问题。