Question

My array with the images stored in:

int image[] = {R.drawable.natsu, R.drawable.erza, R.drawable.gray, R.drawable.lucy, R.drawable.gajeel, R.drawable.juvia, R.drawable.laxus, R.drawable.jellal, R.drawable.cana, R.drawable.mira, R.drawable.elfman, R.drawable.wendy, R.drawable.lisanna, R.drawable.gildarts, R.drawable.makarov, R.drawable.mavis};

Getting the error with: image.setImageResource(image[count + 1]); But it works with the commented out code!

if(compare.equals(ans)){
Toast.makeText(getApplicationContext(), "Correct!", Toast.LENGTH_LONG).show();
//RelativeLayout relative = (RelativeLayout) findViewById(R.id.relative);
//relative.setBackgroundResource(image[count+1]);
ImageView image = (ImageView) findViewById(R.id.iVAnim);
image.setImageResource(image[count + 1]);

et.setText("");
points = points + 10;

point.setText("You have " + points + " points!");}
Was it helpful?

Solution

You have a name clash, that is, you have two things with a same name:

int image[] = ...

and

ImageView image = ...

Rename either of them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top