How can I make this work?
int resId = getResources().getIdentifier("image" + passedVar, "drawable", "com.fnesse.beachguide");
if (resId == null) {
image.setBackgroundResource(resId);
} else {
image.setImageResource(R.drawable.defaultimage);
}
I’m getting the correct response back from getResources and I can display an image but if the image doesn’t exist I would like to display a default image instead of nothing?
Cheers,
Mike.
You got the if/else flipped. Also, invalid resource ID value is 0, not null. Replace with