无法从布局文件夹中引用布局

时间:2012-09-10 15:44:48

标签: java android xml android-layout

我在布局文件夹中有一个名为“activity_qrtest”的布局。当我尝试在类中引用这个布局时如下:

setContentView(R.layout.activity_qrtest);

eclipse用红色突出显示布局名称“activity_qrtest”,这意味着它不可用。

cosole输出:

[2012-09-10 17:15:15 - QRTest] ERROR: resource directory 'D:\workspaceQR\QRTest\res'  
does not exist 
[2012-09-10 17:26:48 - QRTest] 'default' is not a best match for any device/locale  
combination.
[2012-09-10 17:26:48 - QRTest] Displaying it with 'Locale Language ___Region __,  
sw320dp, w320dp, h533dp, Normal Screen, Long screen aspect ratio, Portrait   
Orientation, High Density, Finger-based touchscreen, Soft keyboard, No keyboard,  
Exposed navigation, Trackball navigation, Screen resolution 800x480, API Level 16'   
which is compatible, but will actually be displayed with another more specific   
version of the layout.
[2012-09-10 17:28:41 - QRTest] AndroidManifest.xml file missing!

任何解决此类问题的建议。

2 个答案:

答案 0 :(得分:1)

检查控制台视图中activity_qrtest.xml文件中是否有任何错误。很可能你的xml不正确。另外,请尝试Project|Clean

答案 1 :(得分:0)

确保您在活动中导入YourApplication.R而不是Android.R,它们有时会混淆。

另外,您确定从正确的上下文/活动中调用setContentView吗?有时它有助于这样调用它(我现在无法测试它,但我的记忆告诉我它的工作原理如下):

((Activity)getApplicationContext()).setContentView(R.layout.mylayout);