(TableLayout)findViewById(空指针异常 [英] (TableLayout)findViewById( null pointer exception
问题描述
我寻找答案整天,但是当我试图让我有空表格的布局。
我发现,它可能是另一个表的布局具有相同名称的信息,但只有一个。
我的.xml文件:
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 :
和我的code是这里 layout6 =(TableLayout)findViewById(R.id.shdslResultsTableLayout);
layout6.setVisibility(0);
and my code is here layout6 = (TableLayout)findViewById(R.id.shdslResultsTableLayout);
layout6.setVisibility(0);
总是以空指针结束。
请帮助。
always ends up with null pointer. Please help.
推荐答案
如果 findViewById()
返回一个NPE,尝试一些这些:
If findViewById()
is returning a NPE, try some of these:
- 清洁通过工程项目 - >清除... - >检查项目 - >确定
- 确保您的ID绝对没有拼写错误
- 确保的内容查看正在显示正确的布局,其中
TableLayout
存在 - 确保您
的setContentView
在findViewById
- 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
beforefindViewById
我假设我已经列出第三选项是最有可能您的问题。
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.
这篇关于(TableLayout)findViewById(空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!