Android programming error


I am using 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 the error message "com.example.helloandroid.R.id could not 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 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!

+3
source share
2 answers

Such things accidentally happen sometimes even without any errors, so first try cleaning your project to forcibly complete the recovery and regeneration of R.java.

, , . com.example.helloandroid.R , , com.example.HelloAndroidTest, , . gen/ .R.java, com.example.helloandroid, - R , .

+4

R.java( ) HelloAndroid, HelloAndroidTest.

<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
/>

, .

android.id:"@+id/textview"

<TextView  
    android:id="@+id/textview"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
/>
+1

Source: https://habr.com/ru/post/1776310/


All Articles