获取 android.content.res.Resources$NotFoundException: 即使资源存在于 android 中也会出现异常 [英] Getting android.content.res.Resources$NotFoundException: exception even when the resource is present in android
问题描述
请让我知道哪里出错了.
Please let me know where I am going wrong to get the error.
我正在创建一个应用程序,它的一项活动只能处于横向模式.所以我在 AndroidManifest.xml 文件中添加了以下内容
I am creating an app which have one of its activity to be only in landscape mode. So I added the following in AndroidManifest.xml file
<activity android:name=".LandScapeImageActivity" android:screenOrientation="landscape"></activity>
我创建了一个像
/res/layout-land
/res/layout-land
并在其中添加一个名为 see_today_landscape_layout 的布局.
and add a layout called see_today_landscape_layout in it.
并在 onCreate()
中添加了以下内容
and in onCreate()
I added the following
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.see_today_landscape_layout);
....
}
但是当我运行我的应用程序时,我收到以下错误
But when I run my app I am getting the following error
02-06 13:46:14.358: E/AndroidRuntime(13286): FATAL EXCEPTION: main
02-06 13:46:14.358: E/AndroidRuntime(13286): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mid.kew.activities/com.mid.kew.activities.LandScapeImageActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f03002b
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4066)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.access$2400(ActivityThread.java:135)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2140)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.os.Looper.loop(Looper.java:144)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.main(ActivityThread.java:4937)
02-06 13:46:14.358: E/AndroidRuntime(13286): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 13:46:14.358: E/AndroidRuntime(13286): at java.lang.reflect.Method.invoke(Method.java:521)
02-06 13:46:14.358: E/AndroidRuntime(13286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-06 13:46:14.358: E/AndroidRuntime(13286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-06 13:46:14.358: E/AndroidRuntime(13286): at dalvik.system.NativeStart.main(Native Method)
02-06 13:46:14.358: E/AndroidRuntime(13286): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f03002b
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.content.res.Resources.getValue(Resources.java:892)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1869)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.content.res.Resources.getLayout(Resources.java:731)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-06 13:46:14.358: E/AndroidRuntime(13286): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.Activity.setContentView(Activity.java:1654)
02-06 13:46:14.358: E/AndroidRuntime(13286): at com.mid.kew.activities.LandScapeImageActivity.onCreate(LandScapeImageActivity.java:103)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
02-06 13:46:14.358: E/AndroidRuntime(13286): ... 12 more
我在 R.java 中交叉检查,它具有 ID 为 7f03002b 的资源,异常正在寻找该资源并且它存在于那里...
I crossed checked in R.java and it has the resource with the ID 7f03002b which the exception is looking for and it is present in there...
我清理并重建项目 5 次,但问题仍然存在.
I cleaned and rebuild the project for say 5 times, but still the issue occurs.
奇怪的一点是,这昨天有效,今天无效.代码是一样的.
Strange point is that this was working yesterday and it's not working today. The code is the same.
推荐答案
- 在 Eclipse 中,转到 Project > Clean...
- 选择您的项目,然后按 OK
- 重新启动应用
如果再次发生,请删除 r.java 文件.它会自动生成.
if it happens again delete the r.java file. it will generate automatically.
这篇关于获取 android.content.res.Resources$NotFoundException: 即使资源存在于 android 中也会出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!