2012-05-03 10 views
1

私はちょうどアンドロイドで遊んで始めました。私は何ができるのかを見極めようとしています。私は最初のアンドロイドのチュートリアルに従っていた:http://developer.android.com/training/basics/firstapp/index.html最後に、プログラムでTextViewを定義する。私は新しいレイアウトで定義することが、これを変更したいので、私はこれを書いた(それがdisplay_message.xml命名された):アクティビティのあるレイアウトを使用する

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView android:id="@+id/text_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 


</LinearLayout> 

そしてDisplayMessageとクラスで、私はこれにそれを変更:

public class DisplayMessage extends Activity { 

     @Override 
     public void onCreate(Bundle savedInstanceState) 
     { 
      super.onCreate(savedInstanceState); 
     setContentView(R.layout.display_message); 

     // Get message from intent 
     Intent intent = getIntent(); 
     String message = intent.getStringExtra(FirstActivity.EXTRA_MESSAGE); 

     // Get the text view 
     TextView textView = (TextView) findViewById(R.id.text_view); 
     textView.setText(message); 
    } 

} 

しかし、Eclipseは、R.layout.display_messageが何であるかわからず、R.id.text_viewが何であるかも分かっていません。私はそれらを何か定義する必要がある別の場所がありますか?私はどこでうんざりしたのですか?

+0

プロジェクトをクリーニングしてみてください。 Eclipseには、R.javaファイルのリフレッシュに問題があることがあります。 – robertly

答えて

2

正しいようですが、インポートされたRクラスが正しいかどうかを確認してください。 Eclipseはandroid.Rをインポートすることがありますが、インポートする必要のあるRファイルはyour.package.name.Rです。

+0

ログcatトレースを出力できますか –

関連する問題