I am doing the Android "Hello, Testing" Tutorial using Eclipse Galileo. (http://developer.android.com/resources/tutorials/testing/helloandroid_test.html) When I try to compile and run the program I get an error saying "com.example.helloandroid.R.id cannot be resolved".
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());
}
}
Thanks for any help/advise you can offer!
Edit R.java (found in gen) of HelloAndroid project not HelloAndroidTest. Find this block
Here the issue is there is no id specified. just add
i.e
This kind of thing seems to randomly happen sometimes even without anything done wrong, so first try cleaning your project to force a complete rebuild and regeneration of R.java.
If that doesn't fix it, you may want to start over and be very sure you follow the instructions for project setup exactly. Your explicit reference to com.example.helloandroid.R requires that your project be named that, and not com.example.HelloAndroidTest as it might end up if that's your main class. If you open up the gen/ folder and see an .R.java that isn't in the com.example.helloandroid package that's your problem - the package of the generated R class and the absolute or relative name you refer to it by need to match.