(TableLayout)findViewById( null pointer exception

别说谁变了你拦得住时间么 提交于 2019-12-12 12:24:25

问题


I search for answer all day long, but when i try to get the table layout i am having null. I found info that it may be another table layout with same name, but there is only one. My .xml file :

my xml

and my code is here layout6 = (TableLayout)findViewById(R.id.shdslResultsTableLayout); layout6.setVisibility(0);

always ends up with null pointer. Please help.


回答1:


If findViewById() is returning a NPE, try some of these:

  • Clean the project via Project -> Clean... -> check your project -> OK
  • Ensure you have absolutely no spelling errors in the ID
  • Make sure the contentView is displaying the correct layout where the TableLayout exists
  • Make sure you setContentView before findViewById

I'm assuming the 3rd option I've listed is most likely your problem.

Re-cleaning the project may also help after each of these steps.




回答2:


Please make sure you call the right layout in the setContentView method, and make sure you call setContentView BEFORE calling findViewById.

If you made that, then try to clean / rebuild.

Hope this will help you



来源:https://stackoverflow.com/questions/11671409/tablelayoutfindviewbyid-null-pointer-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!