我的数组中存储的图像为:
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};
获取错误:image.setImageResource(image [count + 1]); 但它适用于注释掉的代码!
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!");}
答案 0 :(得分:1)
你有一个名字冲突,也就是说,你有两件同名的东西:
int image[] = ...
和
ImageView image = ...
重命名其中任何一个。