Java – nosuchmethoderror on some operating system versions
•
Java
I don't know why I only receive this error on some Android versions (lower than 5.0)
I called:
myImageView.setImageDrawable(getResources().getDrawable(R.drawable.image,null));
So I get a nosuchmethoderror What should I do?
Solution
Use this
myImageView.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.image));
Not this
myImageView.setImageDrawable(getResources().getDrawable(R.drawable.image,null));
edit
When you use setimagedrawable (getresources() getDrawable(R.drawable.image,null)); This will display the following error
Notice setimagedrawable (getresources()) getDrawable(R.drawable.image,null)); This method is added in API level 21
You can read more about contextcompat
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码