Android開発を始めたばかりで、すでに壁にぶつかっています。私はオンラインやこのウェブサイトで多くのことを見回してきましたが、私に合った答えが見つからないようです. これまでにアクティビティ ファイルに書き留めたのは、次の内容だけです。
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class CommanderActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById( R.id.button_id );
}
}
エラーが発生するのは、コードの最後の行 ( R.id.button_id ) です。私の 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" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/Parameters"
android:onClick="openParameters" />
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/Waves"
android:onClick="openWaves" />
</TableRow>
<TableRow>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/MoreParameters"
android:onClick="openMoreParameters" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/Status"
android:onClick="openStatus" />
</TableRow>
<TableRow>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/Operations"
android:onClick="openOperations" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/Monitor"
android:onClick="openMonitor" />
</TableRow>
<TableRow>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/CEBus"
android:onClick="openCEBus" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/Advanced"
android:onClick="openAdvanced" />
</TableRow>
</TableLayout>
</LinearLayout>