0

onClickListener メソッドに問題があります。それが呼び出されると、アプリケーションがクラッシュします。私は解決策を探していましたが、私のコードには言われたことがすべてあるようです。

public class Sudoku extends Activity implements OnClickListener {

   @Override
   public void onCreate(Bundle savedInstanceState) 
   {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_sudoku);
      View continue_button = findViewById(R.id.continue_button);
      continue_button.setOnClickListener(this);
      View new_button = findViewById(R.id.new_button);
      new_button.setOnClickListener(this);
      View about_button = findViewById(R.id.about_button);
      about_button.setOnClickListener(this);
      View exit_button = findViewById(R.id.exit_button);
      exit_button.setOnClickListener(this);
   }

   // ...

   public void onClick(View v) 
   {
      switch (v.getId()) 
      {
      case R.id.about_button:
         Intent i = new Intent(this, About.class);
         startActivity(i);
         break;
      }
   }
}

--

public class About extends Activity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_about);
   }
}

そして主な活動:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/background"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="30dip"
    tools:context=".Sudoku" >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center" >
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/main_tittle" 
            android:gravity="center"
            android:textColor="@color/main_tittle"
            android:textSize="25sp"
            android:layout_marginBottom="25dip"/>
        <Button 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/continue_label" />
        <Button 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/new_game_label" />
        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/about_label" />
        <Button 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/exit_label" />
    </LinearLayout>
</LinearLayout>

私は Android/Java プログラミングの初心者です。ご容赦ください。

4

3 に答える 3