Reputation: 1
I'm tring to get an id of the picture by name
someId = "hd_2"
Resources.getSystem().getIdentifier(someId, "drawable", getPackageName());
public static final class drawable {
...
public static final int hd_2=0x7f020088;
...
}
Why it might return java.lang.IllegalArgumentException : Invalid method?
update:
I moved Resources.getSystem().getIdentifier
from onCreate to onStart, now it returns 0.
Upvotes: 0
Views: 1138
Reputation: 111
Maybe this can help you: https://stackoverflow.com/a/15488321/3633665
int resId=YourActivity.this.getResources().getIdentifier("res_name", "drawable", YourActivity.this.getPackageName());
Upvotes: 0
Reputation: 63293
From the documentation on Resources.getSystem()
:
Return a global shared Resources object that provides access to only system resources (no application resources), and is not configured for the current screen (can not use dimension units, does not change based on orientation, etc).
You are looking in the wrong Resources
object. You need to get the instance from your current Context
. Something like:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Resources res = getResources();
int resId = res.getIdentifier(someId, "drawable", getPackageName());
}
Upvotes: 1