1

I am trying to select image from gridview and display it on other intent. I saw this solution : Select image from gridview and display it on other intent

But I have an error, using the debugger I was able to find that my appli/program quit a this line :

mImage.setImageResource(Constants.mThumbIds[index]);

I checked index's number is good.

My code : DisplayActivity.java :

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    Bundle bdl=getIntent().getExtras();
    int index=bdl.getInt("Index");      
    ImageView mImage = (ImageView) findViewById(R.id.mImgView1);
    int test = Constante.mThumbIds[index];

    mImage.setImageResource(Constante.mThumbIds[index]);

    setContentView(R.layout.display);
}

Constante.java

public class Constante {
// references to our images
public static Integer[] mThumbIds = {
     R.drawable.sample_2, R.drawable.sample_3,
     R.drawable.sample_4, R.drawable.sample_5,
     R.drawable.sample_6, R.drawable.sample_7,
     R.drawable.sample_0, R.drawable.sample_1,
     R.drawable.sample_2, R.drawable.sample_3,
     R.drawable.sample_4, R.drawable.sample_5,
     R.drawable.sample_6, R.drawable.sample_7,
     R.drawable.sample_0, R.drawable.sample_1,
     R.drawable.sample_2, R.drawable.sample_3,
     R.drawable.sample_4, R.drawable.sample_5,
     R.drawable.sample_6, R.drawable.sample_7
};}
4

1 回答 1

1

您的 ImageView 可能为空。尝试将 setContextView 放在 super 方法之后。

于 2012-11-19T04:03:55.687 回答