10Answers
  • 5
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Resources NotFoundException?

I'm getting crash reports from android marketplace:

android.content.res.Resources$NotFoundException: Resource ID #0x....

I get about 17 of these a week. It's pointing me to the following in my code:

context.getResources().getDrawable(R.drawable.foo);

That resource is definitely present in my /drawable folder. I have several hundred thousand installs, I'm not sure how this could be failing for some users, but working for the vast majority. I'd like to find out what's going on, because they can't use the app in this state. Any ideas?

Thanks

--------- Update ----------------------

Also I can see the entry for the drawable in question in my R.java file, looks like:

public static final int foo=0x7f020034;

I do a clean build of the project, then straight after that do my release build (no code modification in between to give the automatic eclipse build stuff possibly let the R file go awry)

Thanks

    • This can be obvious, but do you have the "Build Automatically" check in Eclipse selected? If you don't use Eclipse, did you regenerate the resource classes after modifying them? Can you show us your R class?
      • 2
    • Hi yes I do have "build automatically" checked, but I make sure to do a clean build before every release. I can see the resource entry present for that drawable in R.java (pasted above) Thank you
    • I don't see anything pasted, but if you say the entry is there... Are the package shown in R correct (same as your Activity)?
    • Hey, yes same package. If the package was wrong or the entry were missing in the R file, I was thinking that all the other installs would also be crashing. It happens to just a few users, can't understand why, so frustrating!
      • 2
    • I get about 80 a week right now. I can not see why! This is being caused from loads of all and any of my activities, not just one specific resource. Obviously we go through a full regression testing before release and never see this issue. Where could it be coming from? Is this a bug in android? It is being seen on ALL types of device and supported OS (2.2+).

I got this exception:

Resources$NotFoundException: String resource ID

when I was using setText with an int value. I had to convert it to String.

Before:

myTextView.setText(obj.SomeIntProperty);    

After:

myTextView.setText(String.valueOf(obj.SomeIntProperty));
  • 46
Reply Report
    • I've been trying to resolve this problem for hours. When i tried to do textView.setText(array.length) i got this exception. textView.setText(""+array.length) is the solution

Is the crash reports coming from version <=1.6, and you have certain resources only in qualified folders, i.e. "drawable-mdpi" instead of just "drawable"? If so then read about "Known issues" at the bottom of this page.

  • 12
Reply Report
      • 1
    • Ah dang I do have some resources in /drawable-mdpi and others just in /drawable. I've been running this on a 1.6 emulator for some time though, and never had any issue with it (my min target is 1.6, so users shouldn't even be able to run on 1.5). Could that be it? Shouldn't it be crashing on the emulator then, too?
      • 2
    • Yes, it should crash on the emulator as well. I'm using an 1.6-emulator myself to track down these kind of bugs. If you have tested carefully with the emulator, then you can exclude this bug :/
      • 2
    • Hmm yes actually I see now that the marketplace is saying that this error is happening on Nexus One, Droid, then others. I think Nexus One was running minimum 2.0, same for Droid. Argh.

The same problem I found on my application today morning and found a very simple solution to this. the problem looks big and complicated but it's not.

Steps which I followed are

  1. Delete the bin folder it self
  2. Clean the project
  3. Remove application from your device
  4. Run the application and check your scenario.

According to me it should not give this exception again.

Reason : When you build the application R.java contains all the memory address and it happens that those address are invalid for next run.

Second Reason : When you have the application which supports lanscape and portrati mode both and if you have not wrote the XML file for either of them then it's the possibility that may lead to this kind of crash. and there are pretty much chances of OutoFmemory and Memory leak issues when you have to support both the modes. please think on this as well.

  • 2
Reply Report
      • 2
    • For me anyway - this is not useful. I am getting these crash reports from live projects on the app store. I have never seen this during testing or my own usage of the live version using various devices (which are the same devices/os's as some of the reports being sent it). This does not seem to be related to one specific resource/address - for me - as I have seen crash reports when getting all manner of resources - could this be caused by the OS throwing OutOfMemory exceptions? If so I am not getting OOM crashed / stack traces.
    • So are you saying that - This could be being caused because I am loading a layout such as main.... except this layout is NOT included in the standard layout folder instead it is included within layout-normal-port, layout-large-port and layout-xlarge-port & land (I have set the orientation so it must fit within one of these) - could it be because the devices are unable to figure out their own configurations and try taking the resource from the layout folder? 0- interestingly i am seeing some reports on devices which i Have tested on.
    • Yes. exactly what happens if application trys to load the XML from the respective folder while the orientation is changed but some times if the xml is not places it gives this kind of exception

This have occurred several times especially on phones with low density. I also noticed that it mostly happens with 9-patch images.

My solution was to include 9-patch images in as much density resource folders as I could (mdpi, ldpi, hdpi, xdpi).

  • 2
Reply Report

Heh, no idea, I'm actually working on a similar issue, but it could be it. It's worthwhile mentioning that while the device can upscale resources and layouts, it cannot downscale them. So if you have minimum values, set them in the AndroidManifest.xml. Try adding layout-ldpi and layout-small first.

A useful technique for logging which layout got loaded is to attach an android:tag to every root container of your layout XML file, and in onCreate() after setting setContentView(R.id.layout) just print the value of the tag. It will tell you which got loaded - you still have to plug the hole by adding all possible combinations, if just for debug purposes.

also, rename your drawables to drawables-nodpi folder to ensure no drawables are missing. this turns off internal scaling, makes APKs smaller and doesn't "pick" from any other drawable folder.

once you figure out whether it's the layout or drawable, additional metrics will help you find the root cause. for now, check the layouts first with "always use" drawables.

on monday when i get back to the office I'll post you the metrics code used to measure data captured in this thread - Which part of Android is in charge of picking a correct resource profile?

  • 1
Reply Report

You have included certain codes that reference content from Android SDK.

For example, I faced a similar issue once and when I removed the line

android:background="?android:attr/actionBarItemBackground"

from my xml, everything works fine again.

  • 1
Reply Report

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. Such is life!

In my case, ResB was defined in the values-swxxxdp but not in values. Hence I was getting this exception on phones but not on tablets.

  • 0
Reply Report

In my case I had a layout file that lead to the crash:

I got the following log-

enter image description here

That showed this link to my actual code:

enter image description here

Which is this line of code:

enter image description here

I checked my file navigator folder names as suggested by the most popular answer and it looked like the resource that is supposedly missing is in the normal layout folder

enter image description here

but when looking under the Project file navigator rather than the Android file navigator I was able to see that not only was the supposedly missing resource file not in the normal layout folder, but I didn't even have a layout folder without a special extension.

enter image description here

Adding an Android Resource Directory to the res folder and calling it layout and then pasting over the resources from your speciality folder (ex. layout-sw720dp) into it fixed the issue for me.

enter image description here

This solution will also work for other folders as suggested such as not having files in drawable and only having them in drawable-xxhdpi can be fixed by moving the file into drawable and tweaking it as needed. Good luck folder fiends!

  • 0
Reply Report

The error can happen when portrait XML layout file is not defined. It doesn't happen all the time, but happens for example if user quickly turns off and on the phone, I suppose in that case the system calls the onCreate in portrait orientation, before calling onCreate in landscape.

  • 0
Reply Report