0

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?

Norbert
  • 347
  • 2
  • 4
  • 12

5 Answers5

2

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.

Brijesh Thakur
  • 6,768
  • 4
  • 24
  • 29
  • I know this is old but spent atleast 3 days on this issue. Thank you very much, you helped me. I would have never thought its so simple to fix – user3004826 Jun 08 '16 at 07:44
0
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));
0

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)
Code Poet
  • 11,227
  • 19
  • 64
  • 97
  • It does compile and the strangest thing is that in the majority of cases ( 99%) it does not crash and it does well. However, there is this one percent of users who can't start the app due to this bug. I am wondering what could be making it. – Norbert Dec 04 '11 at 14:32
  • but did you try accessing your string resources the way I mentioned? I think the way your accessing your strings might be wrong. – Code Poet Dec 04 '11 at 14:43
  • The string accessing example was just an example, I haven't seen a report that it actually crashes there. I meant that every where that I use a resource ID I use it trough "R" – Norbert Dec 04 '11 at 15:05
0

Except

setContentView(R.layout.some_custom_layout);

try using

setContentView(yourpackagename.R.layout.some_custom_layout);

that helped me a lot of times.

Markonato
  • 61
  • 3
0

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

Vladimir
  • 3,774
  • 3
  • 23
  • 27