@layout/activity_main does not contain a declaration with id XXX,findViewById(R.id.XXX)爆红解决方法...

问题描述:

在MainActivity.java中,通过id寻找checkbox,明明能显示这个组件的id,Ctrl+点击也能跳转过去,但是就是爆红,提示@layout/activity_main does not contain a declaration with id XXX

@layout/activity_main does not contain a declaration with id XXX,findViewById(R.id.XXX)爆红解决方法..._第1张图片

 @layout/activity_main does not contain a declaration with id XXX,findViewById(R.id.XXX)爆红解决方法..._第2张图片

 成功跳转@layout/activity_main does not contain a declaration with id XXX,findViewById(R.id.XXX)爆红解决方法..._第3张图片

解决方法:

原来是setContentView(R.layout.activity_main);没有更改。将setContentView(R.layout.activity_main);修改为所找的id所在的文件名,即可找到。

@layout/activity_main does not contain a declaration with id XXX,findViewById(R.id.XXX)爆红解决方法..._第4张图片

你可能感兴趣的:(android)