GermainGum
GermainGum

Reputation: 1399

Error when "Select image from gridview and display it on other intent"

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

Upvotes: 1

Views: 196

Answers (1)

wang
wang

Reputation: 98

Your ImageView may be null. Try to put setContextView right after super method.

Upvotes: 1

Related Questions