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));

  1. Ok I saw your logcat image capture. Well done.

  2. 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?

  1. Your code should work. I guess there is a bad reference in your R. Clean your project and recreate your R.

Eclipse: ProjectClean

Android Studio: BuildClean Project


getResources().getDrawable is deprecated.

You can try ContextCompat.getDrawable:

image.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.myimage));

Tags:

Android