これは、コードを使用した最初のAndroidアプリであるため、非常に単純なものであると確信しています(hello worldの例では、XMLの文字列に値を割り当てるだけでした)。私の問題は、変数でボタンの参照を取得しようとしたときに、R.idのようなIDが定義されていないことです。
コンパイラエラーは、以下のコードのコメントにあります。
package com.geeksonhugs.simplecalc;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
public class MainActivity extends Activity
{
private Button AddButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AddButton = (Button)findViewById(R.id.btnAdd);
//"Unknown member 'id' of 'com.geeksonhugs.simplecalc.R'"
//AddButton.setOnClickListener(this);
}
}
XMLレイアウトファイル:
<?xml version='1.0' encoding='utf-8' ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LayoutRoot"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txtFirstNum"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/strFirstNum" />
<EditText
android:id="@+id/edtFirstNum"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="" />
<TextView
android:id="@+id/txtSecondNum"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/strSecondNum" />
<EditText
android:id="@+id/edtSecondNum"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="" />
<Button
android:id="@+id/btnAdd"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/strAdd"
android:gravity="center" />
<TextView
android:id="@+id/txtResult"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="" />
</LinearLayout>