0

簡単なプログラムを書いていますが、プログラムを実行するとプログラムにエラーが発生します。レイアウト フォルダーに activity_main.xml がありますが、プログラムに activity_main のエラーがあります。なんで?何が問題ですか?

エラー: activity_main を解決できないか、フィールドではありません web_view を解決できないか、フィールドではありません

activity_main.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">
<WebView
    android:id="@+id/web_view"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1.0" />
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button1"/>
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button2"/>
    </LinearLayout>
    </LinearLayout>

MainActivity.java

public class MainActivity extends Activity {
Button button1;
Button button2;
WebView mWeb;
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWeb= (WebView)findViewById(R.id.web_view);

    button1=(Button)findViewById(R.id.button1);
    button2=(Button)findViewById(R.id.button2);
    button1.setOnClickListener(onClickListener);
    button2.setOnClickListener(onClickListener);

}
private OnClickListener onClickListener=new OnClickListener(){
    public void onClick(View v){
        //don't work something  
        }
};
}
4

2 に答える 2

1

時々Eclipseが追加します

android.R をインポートする

インポートのリストに。これはエラーであり、削除する必要があります。削除すると、説明されている問題が解決する場合があります。

于 2013-05-08T04:18:43.517 に答える
0

以下を試してください:

  1. ワークスペースをクリーンアップして、もう一度実行してみてください
  2. R.java がgenフォルダーに作成されているかどうかを確認し、そこにあるパッケージ名は何ですか?
  3. Web ビューと R.Java が同じパッケージ名を共有していることを確認してください。そうでない場合は、Web ビューのパッケージ名を変更するか、manifest.xml を変更してください。
  4. Eclipse を閉じてもう一度開いてみてください。
于 2012-11-10T00:41:47.243 に答える