android里关于findViewById不能正常获取控件对象的问题

今天写了以下代码:android

Button bt1=(Button)findViewById(R.id.btn1);this

bt1.setOnClickListener(bt1lis);指针

 

运行后报空指针错误。List

后来把错误

Button bt1=(Button)findViewById(R.id.btn1);

改成

Button bt1=(Button)this.findViewById(R.id.btn1);

就没问题了。

更为有意思的是,加上this跑起来之后,再把this去掉,也不报错了,android闹脾气了?

相关文章
相关标签/搜索