Why Getdrawable() Doesn't Work On Some Android Devices?
I am getting 'nosuchmethod error' on some user's phones (eg. Motorola Razr i) but it works fine on my HTC. Below is the code. Drawable rBlack; rBlack = getResources().getDrawable(R
Solution 1:
I'm going to bet it is failing on getDrawable(R.drawable.rblack, getTheme());
which was added in API 21. Change that line to:
if(android.os.Build.VERSION.SDK_INT >= 21){
rBlack = getResources().getDrawable(R.drawable.rblack, getTheme());
} else {
rBlack = getResources().getDrawable(R.drawable.rblack);
}
Solution 2:
ContextCompat.getDrawable(Context context, intid)
Solution 3:
Try adding the following line of code:
context.getResources().getDrawable(R.drawable.your_image_name);
Post a Comment for "Why Getdrawable() Doesn't Work On Some Android Devices?"