0

こんにちは、私はアンドロイドが初めてで、単純な数独アプリケーションを実行しようとしています。「about」ボタンをクリックするたびに、applocationが停止してメニュー画面に戻る傾向があります。誰でもクラッシュの問題は何ですか??

以下は私のコードです:

数独.java

public class Sudoku extends Activity implements OnClickListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sudoku);
    View continueButton=findViewById(R.id.button1);
    continueButton.setOnClickListener(this);
    View newButton=findViewById(R.id.button2);
    newButton.setOnClickListener(this);
    View aboutButton=findViewById(R.id.button3);
    aboutButton.setOnClickListener(this);
    View exitButton=findViewById(R.id.button4);
    exitButton.setOnClickListener(this);
}

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

            }
          }
        @Override
           public boolean onCreateOptionsMenu(Menu menu) {
              super.onCreateOptionsMenu(menu);
              MenuInflater inflater = getMenuInflater();
              inflater.inflate(R.menu.menu, menu);
              return true;
           }

 }

について.java

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

about.xml:

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

文字列.xml:

<?xml version="1.0" encoding="utf-8"?>

<string name="app_name">Sudoku</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Application Sudoku</string>
<string name="continue_label">Continue</string>
<string name="new_game_label">New Game</string>
<string name="about_label">About</string>
<string name="exit_label">Exit</string>
<string name="about_title">About Android Sudoku</string>
<string name="about_text">\Sudoku is a logic-based number placement puzzle.

部分的に完成した 9x9 グリッドから始めて、各行、各列、および 3x3 ボックス (ブロックとも呼ばれる) のそれぞれに 1 から 9 の数字が 1 回だけ含まれるように、グリッドを埋めることが目的です。

activity_sudoku.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@color/background"
tools:context=".Sudoku" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    android:textStyle="italic" />

<TableLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:stretchColumns="*">
    <TableRow >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="22dp"
    android:text="@string/continue_label"
    android:textStyle="italic"
     />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button1"
    android:layout_below="@+id/button1"
    android:layout_marginTop="21dp"
    android:text="@string/new_game_label" 
    android:textStyle="italic"
    />


</TableRow>
<TableRow >

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="@string/about_label"
         />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="@string/exit_label"
         />

</TableRow>
</TableLayout>

</RelativeLayout>

数独 Manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.sudoku"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="org.example.sudoku.Sudoku"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="org.example.sudoku.About"
        android:label="@string/about_title"
        android:theme="@android:style/Theme.Dialog">
    </activity>
</application>

</manifest>
4

2 に答える 2

0

インテント フィルターを manifest.xml に追加してみてください。Android プログラムの起動中に、この問題に何度も直面しました。次のように追加します。

<activity
    android:name="org.example.sudoku.Sudoku"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name="org.example.sudoku.About"
    android:label="@string/about_title"
    android:theme="@android:style/Theme.Dialog">
    <intent-filter>
        <action android:name="org.example.sudoku.About" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

Sudoku.java の後半で、この部分を更新します。

case R.id.button3:
        Intent i = new Intent(this, About.class);
        startActivity(i);
        break;

上記を次のように更新します。

case R.id.button3:
        startActivity(new Intent("org.example.sudoku.About"));
        break;

これで問題が解決するはずです。

于 2013-05-21T06:20:24.030 に答える