gpt4 book ai didi

java.lang.NullPointerException : Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference 异常

转载 作者:行者123 更新时间:2023-11-30 01:16:57 27 4
gpt4 key购买 nike

<分区>

java.lang.NullPointerException:尝试在空对象引用上调用虚方法“void android.widget.ImageView.setImageResource(int)”

我想使第一个 Activity 的图标/图像转移或移动到第二个 Activity ,但出现上述错误。

这是我在第一个actvty中的源代码:

 public void next (View view){
Intent intent = new Intent(this, Products.class);
intent.putExtra("Button ID", btnId);
startActivity(intent);
}

然后在第二个actvty

 btnId = getIntent().getIntExtra("Button ID", btnId);
setContentValues();
}

private void setContentValues() {
ImageView titleImg = (ImageView) findViewById(R.id.imageView_result_title);
View view = (View)findViewById(R.id.layout_goals_goals);

switch (btnId) {
case R.id.imageButton_goals_car:
titleImg.setImageResource(R.drawable.car);
break;
case R.id.imageButton_goals_education:
titleImg.setImageResource(R.drawable.education);
break;
case R.id.imageButton_goals_health:
titleImg.setImageResource(R.drawable.health);
break;
case R.id.imageButton_goals_house:
titleImg.setImageResource(R.drawable.house);
break;
case R.id.imageButton_goals_saving:
titleImg.setImageResource(R.drawable.savings);
break;
case R.id.imageButton_goals_travel:
titleImg.setImageResource(R.drawable.travel);
break;
default:
break;
}
}

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