findViewById在运行时返回null,尽管id存在于XML中

时间:2015-09-05 18:37:13

标签: android xml android-studio r.java-file

我有一个类,我在其中设置了XML布局的ContentView

setContentView(R.layout.car_layout);

然后设置所有成员:

    text1 = (TextView) findViewById(R.id.text1);

    text2 = (TextView) findViewById(R.id.text2);

    textCar = (TextView) findViewById(R.id.textCar);

    textId = (TextView) findViewById(R.id.textId);

一切都符合,但在运行时我遇到崩溃错误,说R.id.textCarnull,但该字段存在100%,并且它在R.java文件中也有值。我尝试更改名称但仍返回null。 试图清理项目,重建它,删除.iml ......没有发生任何事情。

可能是什么问题? (我使用Android Studio)

0 个答案:

没有答案