首页上一页 1 下一页尾页 1 条记录 1/1页
Android Studio下编程错误提示
发表在Android图书答疑
2015-04-28
是否精华
是
否
版块置顶:
是
否
按照3.26章节的例子编写猜鸡蛋程序,再Android Studio 1.1下提示错误:
private ImageView image1;
private ImageView image2;
private ImageView image3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image1 = (ImageView)this.findViewById(R.id.imageView1);
image2 = (ImageView)this.findViewById(R.id.imageView2);
image3 = (ImageView)this.findViewById(R.id.imageView3);
image1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isRight(v, 0);
}
});
错误提示:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
仿真中提示:
[img src=null/img]
很奇怪的是,按照书上和网络上查找的答案,这样编写不应该报错。望高手解答,先谢啦。
private ImageView image1;
private ImageView image2;
private ImageView image3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image1 = (ImageView)this.findViewById(R.id.imageView1);
image2 = (ImageView)this.findViewById(R.id.imageView2);
image3 = (ImageView)this.findViewById(R.id.imageView3);
image1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isRight(v, 0);
}
});
错误提示:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
仿真中提示:
[img src=null/img]
很奇怪的是,按照书上和网络上查找的答案,这样编写不应该报错。望高手解答,先谢啦。