How to set image from PNG based on dynamic drawable name?
I use following code byt getting the error.
I have PNGs:
R.drawable.model_1.png
R.drawable.model_2.png
... and etc
Code
try
{
String imageName = "model_" + uv.categoryID;
int id = context.getResources().getIdentifier(imageName, "drawable", context.getPackageName());
imageView.setImageResource(id);
}
catch(Exception ex)
{
Log.e(TAG, ex);
}
Error
Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference