gpt4 book ai didi

android - "Select image from gridview and display it on other intent"时出错

转载 作者:行者123 更新时间:2023-11-30 03:55:22 25 4
gpt4 key购买 nike

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

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

mImage.setImageResource(常量.mThumbIds[索引]);

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

我的代码:显示 Activity .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 放在 super 方法之后。

关于android - "Select image from gridview and display it on other intent"时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13447331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com