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

Android 尽管id存在于XML中,但findViewById在运行时返回null,android,xml,android-studio,r.java-file,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 = (TextV

我有一个类,在其中设置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.textCar
null
,但该字段100%存在,并且在
R.java
文件中有一个值。我试图更改名称,但它仍然返回一个
null
。 试图清理项目,重建项目,删除
.iml
。。。什么也没发生


有什么问题吗?(我使用Android Studio)

对于多个分辨率,您有相同的布局吗?可能该设备正在拾取的car_layout.xml中不存在此id,从而导致运行时错误发布您的layout.car_layout,xml文件