2010-11-22 12 views
3


Eclipse Galileoを使用してAndroidの「Hello、Testing」チュートリアルを行っています。 (http://developer.android.com/resources/tutorials/testing/helloandroid_test.html)プログラムをコンパイルして実行しようとすると、「com.example.helloandroid.R.idを解決できません」というエラーが表示されます。Androidプログラミングエラー

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());  
    } 
} 

ご協力いただきありがとうございます!

+2

を追加するには、全体のコードを投稿してください。おそらくインポートがありません。 – birryree

答えて

4

この種のことは、間違っていなくても時折ランダムに起こっているようですので、まずプロジェクトをきれいにしてR.javaの完全な再構築と再生成を強制してください。

これで解決できない場合は、最初からやり直して、プロジェクトの設定手順を正確に守ってください。 com.example.helloandroid.Rを明示的に参照するには、プロジェクトがメインクラスの場合は終了する可能性があるため、プロジェクトにはその名前を付け、com.example.HelloAndroidTestではなく名前を付ける必要があります。 gen /フォルダを開いて、あなたの問題であるcom.example.helloandroidパッケージにない.R.javaを参照すると、生成されたRクラスのパッケージと絶対名または相対名が必要に応じて参照します合わせる。

+0

ありがとう!私はそれを試してみましょう! – androidGM

+0

「R」タイプのフィールドタイプ「id」を作成し、「R」タイプの定数「id」を作成 – androidGM

+0

xmlファイルがないか間違ったパッケージに関連付けられているように聞こえます –

1

HelloAndroidプロジェクト(HelloAndroidTestではなく)のR.java(genで見つかった)を編集します。このブロックを見つける

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

ここで問題はIDが指定されていないことです。ただ

android.id:"@+id/textview" 

すなわち

<TextView 
    android:id="@+id/textview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" 
/> 
関連する問題