简体   繁体   中英

Android Resource not found exception

So I am not such a newbie in Programming, Java or Android developing, but I got a strange issue: I have made an application, quite advanced, and have it on market.

For now I have over 1000 installs and I have around 4 or 5 crash reports for a ResourceNotFoundException. The strangest thing is that the line it crashes on is on

setContentView(R.layout.some_custom_layout)

In code I am always referring to resourced by

someTxtView.setText(R.string.some_string)

So I am wondering if I used

mContext.getResources().getDrawable(mContext.getResources().getIdentifier("some_string", "string", "my.example.package"));

would the crash go away?

I was facing the same issue and I fixed it by creating Layout Folder called "layout-small".

Based on resolutions I have created only 2 folders "layout-large" and "layout-medium". But few phones are having lower resolution it doesn't find proper resources as per the resolution. Android OS renders xml resources as per resolution. It goes and find the resources in required folders.

95+ % Android phones having resolution which matches "layout-normal" folder. But still there are Phones having lower resolution. Hence this issue occurred.

For more Details : http://developer.android.com/guide/practices/screens_support.html

Hope this helps your problem.

someTxtView.setText(R.string.some_string)

There you set integer value to text. Its not correctly becouse it search a resousre on this value. You must write

someTextView.setText(getResources().getText(R.string.blabla));

If you are calling setContentView(R.layout.some_custom_layout) from the Activity's onCreate method, you should be good as long as your app compiles (and I assume it does).

AFAIK accessing your string resources via:

someTxtView.setText(R.string.some_string)

is not the way to go. You should be doing this:

getContext().getResources().getString(R.string.some_string)

Except

setContentView(R.layout.some_custom_layout);

try using

setContentView(yourpackagename.R.layout.some_custom_layout);

that helped me a lot of times.

I have one suggestion. Do you use in your layouts android secific resources, such as drawables or something, for example

android:backgroud="@android:drawable/some_android_drawable"

Maybe some vendors don't provide some resources with their firmware, so your app crashs. for example this issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM