“从gridview中选择图像并将其显示在其他意图上时出错”

时间:2012-11-19 03:36:23

标签: android

我正在尝试从gridview中选择图像并将其显示在其他意图上。 我看到了这个解决方案:Select image from gridview and display it on other intent

但是我有一个错误,使用调试器我能够发现我的appli / program退出了这一行:

mImage.setImageResource(Constants.mThumbIds [指数]);

我检查索引的数字是好的。

我的代码: 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
};}

1 个答案:

答案 0 :(得分:1)

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