setImageResource is not working
Updated@
Simon Schubert
answer looks correct.
Otherwise you can also do by accessing getDrawable method from Resources.
Resources resources = getResources();
image.setImageDrawable(resources.getDrawable(R.drawable.myfirstimage));
Ok I saw your logcat image capture. Well done.
Check if the following ids exists in your
R.layout.cards
.img1 = (ImageView) findViewById(R.id.img1); img2 = (ImageView) findViewById(R.id.img2); image = (ImageView) findViewById(R.id.ImageView01);
It looks like one of your images isn't accessable. What exactly is line 55?
- Your code should work. I guess there is a bad reference in your R. Clean your project and recreate your R.
Eclipse: Project → Clean
Android Studio: Build → Clean Project
getResources().getDrawable
is deprecated.
You can try ContextCompat.getDrawable
:
image.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.myimage));