What EXACTLY does $ NotFoundException resources do?

I recently posted a $ NotFoundException resource error here and got the usual general suggestions for deleting the gen folder, clean, updating, etc. etc. There are hundreds (thousands?) Of other programmers who receive the same exception and receive the same offers throughout SO and on the Internet. But I can not find anywhere where anyone describes what this error really means .

The documentation is vague: http://developer.android.com/reference/android/content/res/Resources.NotFoundException.html

Resources $ NotFoundException is a run-time error, so it is supposedly looking for something in the APK file.

  • How are the resources embedded in the APK file during build? We start with an XML file, and then what ...?
  • How do they refer at runtime?
  • What is the relationship between the resource identifier that I see in the debugger and how it is identified in the APK file?
  • What tools (Windows) can I use to check the APK file to find these resources on my own?

Thanks for the answers to any of these questions!

PS - if you think that you have an answer to the original error, please post it there and not for this topic; this is another question.

+7
source share
2 answers
  • Resources can be packaged in various ways from raw materials, optimized for packed byte data. All stuck in one apk. Resource Id helps to find it. During development, the aapt constantly scans the res directory for xml, images, etc. And generates numerical constants in R.java . Read more about the Android build process .

  • At run time, the Resources instance decides where to look, depending on whether its get method is called. The numerical value of Id helps to request a resource mapping and find the right one. Actual data loading is handled by its own low-level code.

  • The debugger can display objects and their fields. To find out what is missing, read the NotFoundException error NotFoundException in logcat. It indicates the hexadecimal value of the resource identifier.

  • ApkTool allows you to deflate the apk file and rebuild the res directory.

Update:

How resources are packaged:

If you have apk and want to see the full resource table, run the aapt tool in the SDK as:

  aapt list -v myApp.apk 

It will display the details as:

 Archive: ./myApp.apk Length Method Size Ratio Offset Date Time CRC-32 Name -------- ------ ------- ----- ------- ---- ---- ------ ---- 468 Deflate 228 51% 0 11-07-12 23:25 29fb0660 res/color/abs__primary_text_disable_only_holo_dark.xml 468 Deflate 228 51% 332 11-07-12 23:25 bae4791a res/color/abs__primary_text_disable_only_holo_light.xml 2942 Stored 2942 0% 280417 10-27-12 16:52 9b5af43b res/drawable-xhdpi/ic_mus.png 2330 Stored 2330 0% 283418 10-27-12 16:52 21f5ba4d res/drawable-xhdpi/ic_pic.png 1556 Stored 1556 0% 285810 10-27-12 16:52 31c3402b res/drawable-xhdpi/ic_vid.png 

You will see a method (deflate, stored, etc.) and an offset in the binary data where the resource is stored, and a length that indicates the number of bytes that will be read after the offset to get this resource.

What a Resources.NotFoundException :

Here is the code that generates it:

 public void getValue(int id, TypedValue outValue, boolean resolveRefs) throws NotFoundException { boolean found = mAssets.getResourceValue(id, 0, outValue, resolveRefs); if (found) { return; } throw new NotFoundException("Resource ID #0x" + Integer.toHexString(id)); } 

Thus, it prints the hexadecimal Id value for which the Resources instance is requested.

Here is the part of R.java :

 public static int absForceOverflow=0x7f010039; 

You can see that Id gets similar Hex values.

Can I solve this error?

The error should not occur in the first place if the build tools compiled by you are completed successfully. There you can do nothing but clean up or restore the project. This is an error in the build tools or resource loader OR data corruption in the apk on the device.

+7
source
  • How are the resources embedded in the APK file during build? We start with an XML file, and then what ...?

Whenever you use @+id/ in your XML or place an element in the strings.xml file or your drawable folder, the Compiler converts all resources in the / res folder to an integer value, which is then placed in R.java.

 2. How are they referenced at runtime? 

Resources reference integer values ​​that are viewed in R.java

3. What is the relationship between the resource identifier that I see in the debugger and how it is identified in the APK file?

In my understanding, this is a relationship that is developing in R. java again.

4. What tools (Windows) can I use to check the APK file to find this resource on my own?

Not sure...

That is all that I have gathered from my understanding. If there are any false statements here, please let me know.

0
source

All Articles