Android.Content.Res.Resources$Notfoundexception

Getting android.content.res.Resources$NotFoundException: exception even when the resource is present in android

  1. in eclipse, go to Project > Clean...
  2. select your project, then press OK
  3. relaunch the app

if it happens again delete the r.java file. it will generate automatically.

How to fix android.content.res.Resources$NotFoundException: Resource ID #0x7f060056

Try to clean and rebuild your project.

If that doesn't work, use this code to set the background

linearLayout.setBackground(ContextCompat.getDrawable(this, R.drawable.img1))

By the way, next time you should post the code directly instead of passing in a link.

I get android.content.res.Resources$NotFoundException: Resource ID #0x0 when I try to parse a layout

It is because you are accessing layoutPicked inside onCreateView() whereas it is initialized in OnStart() method which is called after onCreateView(). So whenever it tries to inflate layout that time the variable
layoutPicked is null.

Problem resolving an android.content.res.Resources error

android.content.res.Resources$NotFoundException: String resource ID #0x601ee924
at android.content.res.Resources.getText(Resources.java:348)
at android.widget.TextView.setText(TextView.java:5848)
at com.tex.lightweatherforecast.Activity.HomeActivity$1.onResponse(HomeActivity.java:66)

As shown above, the exception is raised in HomeActivity in onResponse() method line (66) where you try to set a text into a TextView.

So, In HomeActivity you've:

 time_field.setText(response.body().getCurrent().getDt());

And as per documentation, .getDt() returns an integer, so you can't set it directly to TextView unless you convert it to a String.

To solve this, replace that line of code with one of:

 // 1st
time_field.setText(String.valueOf(response.body().getCurrent().getDt()));

// 2nd
time_field.setText("" + response.body().getCurrent().getDt());

how to resolve android.content.res.Resources$NotFoundException: Resource ID #0x7f070187 type #0x4 is not valid

Ensure the dimensions have a defined unit:

https://developer.android.com/guide/topics/resources/more-resources#Dimension

In your case do as next. Notice the dp postfix after each value:

<dimen name="pageMargin">20dp</dimen>
<dimen name="offset">30dp</dimen>

Resources$NotFoundException Unable to find resource ID #0x7f080043 for Drawable

It might be due to the resource not having a file in the default folder (only in the xxhdpi and ldrtl-xxhdpi folders). The phone on which the app is crashing probably has a different density and the app is deployed/installed as an android app bundle (.aab) which enables google play to remove the resources it deems unnecessary (like this resource which would not be needed for that device given its different density) to reduce bundle size.

A workaround would be to copy that resource into your project (preferably with a different name to prevent other problems) and place it directly under the resources/drawables folder or in all drawables folders depending on its dimensions (if any). This should ensure it is present in all app bundles regardless of their target screen density.


Reply to comment:

Yes, indeed it is a bug though the android gradle plugin might have logged an error/warning in the build logs about the drawable in question not being provided for all densities. The rule/recommendation is to either have a drawable in the drawables folder or have copies (of proportional size) in each of the mdpi, hdpi, xhdpi, xxhdpi folders . In the case of this support library it only provided an xxhdpi version and probably at runtime the library uses the drawable only on xxhdpi devices. This is a 9 patch image so it can safely be copied to drawables without loss of quality.

Ideally most graphics would consist of vector drawables which can/should be placed in drawables without worrying about device density. Be mindful though about the vector drawable's width and height attributes as these will determine how big it will appear on screen and if these attributes are missing the size will be inferred from that of the view (wrap_content might result in the drawable not being visible).
Always be careful to provide resources for all device configurations (densities, screen orientations, ...) when using the aab format to deploy apps because the final archive downloaded by the device will probably have only resources for its density and/or the default ones (drawables, values). In the past (with the apk format) the android runtime would try to scale down a higher density drawable when a drawable for its density and a default one were not available. Now (with aab) that the higher density drawables are left out of the bundle this is no longer possible.

I also think it's a good practice not to use resources from 3rd party libraries directly (like referencing them from your layouts) because they can easily be renamed, moved or deleted (especially with dynamic gradle dependencies) and with the complex/non-deterministic android build system it might not become apparent before the published app crashes on a user's device. If you really need some resource in a library it might be better to copy it to your project. In general it's safer to rely as little as possible on things out of your control.



Related Topics



Leave a reply



Submit