Android “当”时出错;从gridview中选择图像并将其显示在other intent上;

Android “当”时出错;从gridview中选择图像并将其显示在other intent上;,android,Android,我正在尝试从gridview中选择图像并在其他意图上显示它。 我看到了这个解决方案: 但是,我有一个错误,使用调试器,我发现我的appli/程序退出了这一行: setImageResource(Constants.mThumbIds[index]) 我检查了索引的编号是否正确 我的代码: DisplayActivity.java: protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated met

我正在尝试从gridview中选择图像并在其他意图上显示它。 我看到了这个解决方案:

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

setImageResource(Constants.mThumbIds[index])

我检查了索引的编号是否正确

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

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

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

您是否正在接近强制?如果是这样的话,我的异常应用程序崩溃了,但是现在用wang的解决方案修复了它。谢谢你的帮助。你的力量接近了吗?如果是这样的话,我的异常应用程序崩溃了,但是现在用wang的解决方案修复了它。谢谢你的帮助。