Please let me know where I am going wrong to get the error.
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>
I have created a folder like
/res/layout-land
and add a layout called see_today_landscape_layout in it.
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
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...
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.
This exception is thrown by the resource APIs when a requested resource can not be found. [Android.Runtime.Register ("android/content/res/Resources$NotFoundException", DoNotGenerateAcw=true)] public class Resources.NotFoundException : Java.Lang.RuntimeException
Good luck folder fiends! This could also happen if the resource you are referring to (lets call it ResA) is in-turn referring to a resource which is missing (lets call it ResB). Android will raise the ResourceNotFoundException for ResA even though whats really missing is ResB.
Create a folder in your resource directory name "drawable-nodpi" and then move yours all resources in this directory from others drawable directory. Now clean your project and then rebuilt. Run again hopefully it will work this time without any resource not found exception.
However this is incorrect as the method Resources.getSystem () returns a global shared Resources object that provides access to only system resources. How to access resources from top-level functions or classes that don't inherit from Activity then?
For my condition the cause was taking int
parameter for TextView
. Let me show an example
int i = 5; myTextView.setText(i);
gets the error info above.
This can be fixed by converting int
to String
like this
myTextView.setText(String.valueOf(i));
As you write int
, it expects a resource not the text that you are writing. So be careful on setting an int
as a String
in Android.
if it happens again delete the r.java file. it will generate automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With