关于findViewById返回null问题

private Button btn;

btn.findViewById(R.id.btn_submit);

 

当寻找的资源不是主页面的时候,很有可能出现错误。

上一章的实验就出现了差错:https://www.cnblogs.com/Master-Sun/p/14260238.html

在于,

btnSubmit.findViewById(R.id.btn_reg_submit);

改成

btnSubmit=this.findViewById(R.id.btn_reg_submit);

 

 

 

原因

 

 

 

 

 

其他原因和解决方法在https://www.crifan.com/android_findviewbyid_return_null/讲的很清楚。

特别注意inflatefindViewById的区别。

posted @ 2021-01-10 23:56  Master_Sun  阅读(124)  评论(0编辑  收藏  举报