我試圖從我的數組列表中顯示我imageView中的數據。但是,我越來越如何從數組列表中檢索數據到ImageView?
了java.lang.RuntimeException:無法實例活動ComponentInfo {com.example.gorila.sqlite_grid_view/com.example.gorila.AvatarShop.imageView}:顯示java.lang.NullPointerException
我試圖做一個簡單的功能,其中當用戶從我的自定義列表中購買圖像時,圖像存儲的索引將被添加到我的數組列表中,然後將其傳遞到我的imageView活動類,然後用戶將能夠按下用戶可以切換到他們新購買的圖像的按鈕。
因此,它將從MainActivity - > DetailActivity - > imageView去。
主要活動:
int[] avatarImage = {R.mipmap.blademaster,R.mipmap.gunslinger,R.mipmap.pyro,R.mipmap.darthvader};
listView = (ListView) findViewById(R.id.avatarlv);
MyAdapter myAdapter = new MyAdapter(MainActivity.this,titles,harga,avatarImage);
listView.setAdapter(myAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Intent mIntent = new Intent(MainActivity.this,DetailActivity.class);
mIntent.putExtra("title",titles[position]);
mIntent.putExtra("avatarImages",avatarImage[position]);
mIntent.putExtra("harga",harga[position]);
startActivity(mIntent);
}
});
我的詳細活動:
final ArrayList<Integer> list = new ArrayList<Integer>();
btnYes.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if (mymoney > harga) { // when my money is > price of the item
list.add(mBundle.getInt("avatarImages"));
Toast.makeText(DetailActivity.this, "Successfully Bought the avatar", Toast.LENGTH_LONG).show();
Intent intent = new Intent(DetailActivity.this, imageView.class);
intent.putExtra("list1", list);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
else {
Toast.makeText(DetailActivity.this, "Your money is not enough", Toast.LENGTH_LONG).show();
Intent intent = new Intent(DetailActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
});
我的ImageView:
private int current_image_index;
ArrayList<Integer> imageBought = (ArrayList<Integer>)getIntent().getSerializableExtra("list1");
private void buttonClick()
{
imgView = (ImageView) findViewById(R.id.imageView);
buttonSw = (Button) findViewById(R.id.buttonSw);
buttonSw.setOnClickListener(
new View.OnClickListener(){
@Override
public void onClick(View v) {
current_image_index++;
current_image_index = current_image_index % imageBought.size();
imgView.setImageResource(imageBought.get(current_image_index));
}
}
);
}
請幫助。
抱歉,但這不是一項活動?我意圖調用它,它的工作,我得到的唯一問題是無法調用存儲的數組並將其顯示到圖像視圖。 @MacLean Sochor –