我目前正在开发一个应用程序,它允许用户从 GridView 库中选择一个 ImageView 并单独显示它并展示它的所有美感。
GridView 在 fragment 上,然后将数据传递给 Activity 以显示所选图像。我的整个项目一直在进行,直到初始化 ImageAdapter。我收到一条错误消息,指出没有 GalleryView 类型的封闭实例。我试了又试,然后又试了一些,不愿意发布问题,但我离解决问题还差得很远。
public class SingleImageGallery extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_image_view);
Intent i = getIntent();
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ImageView imageView = (ImageView) findViewById(R.id.SingleView);
imageView.setImageResource(imageAdapter.pics[position]);
}
}
最佳答案
错误消息表明您正在尝试实例化一个非静态内部类而不引用包含的外部类。
我猜你的 ImageAdapter
是 GalleryView
中的非静态内部类。您可能应该使 ImageAdapter
static
因为它不需要对 GalleryView
的引用。
关于java - ImageAdapter 没有封闭错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22760148/