我正在使用 Eclipse Galileo 编写 Android“你好,测试”教程。 (http://developer.android.com/resources/tutorials/testing/helloandroid_test.html http://developer.android.com/resources/tutorials/testing/helloandroid_test.html)当我尝试编译并运行该程序时,出现错误“com.example.helloandroid.R.id 无法解析”。
package com.example.helloandroid.test;
import com.example.helloandroid.HelloAndroid;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView;
public class HelloAndroidTest extends ActivityInstrumentationTestCase2<HelloAndroid>
{
private HelloAndroid mActivity; // the activity under test
private TextView mView; // the activity's TextView (the only view)
private String resourceString;
public HelloAndroidTest()
{
super("com.example.helloandroid", HelloAndroid.class);
}
@Override
protected void setUp() throws Exception
{
super.setUp();
mActivity = this.getActivity();
mView = (TextView) mActivity.findViewById(com.example.helloandroid.R.id.textview);
resourceString = mActivity.getString(com.example.helloandroid.R.string.hello);
}
public void testPreconditions()
{
assertNotNull(mView);
}
public void testText()
{
assertEquals(resourceString,(String)mView.getText());
}
}
感谢您提供的任何帮助/建议!
这种事情有时似乎是随机发生的,即使没有做错任何事情,所以首先尝试清理你的项目以强制完全重建和重新生成 R.java。
如果这不能解决问题,您可能需要重新开始,并确保完全遵循项目设置的说明。您对 com.example.helloandroid.R 的显式引用要求您的项目被命名为该名称,而不是 com.example.HelloAndroidTest ,因为如果这是您的主类,它可能最终会出现。如果您打开 gen/ 文件夹并看到 .R.java 不在 com.example.helloandroid 包中,那就是您的问题 - 生成的 R 类的包以及您根据需要引用它的绝对或相对名称匹配。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)