文件包括/src里的About.java和SudokuActivity.java
/res/layout里有:about.xml和main.xml
/res/layout-land里有:main.xml
AndroidManifest.xml代码依次如下,我不太会调试Android程序,光看代码看不出来,求教了,谢谢!!!
估计错误出在.java文件里面,但是实在不知道是哪里。布局应该不会错~求助~~/src/.../About.java
package com.payne.android.SudokuActivity;import android.app.Activity;
import android.os.Bundle;public class About extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
}
}/src/.../SudokuActivity.java
package com.payne.android.SudokuActivity;import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
import android.view.View.OnClickListener;public class SudokuActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); // Set up click listeners for all the buttons
View continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener(this); View newButton = findViewById(R.id.new_button);
newButton.setOnClickListener(this); View aboutButton = findViewById(R.id.about_button);
aboutButton.setOnClickListener(this); View exitButton = findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);
} @Override
public void onClick(View v) {
switch(v.getId()){
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
// More buttons go here (if any) ...
}

}
}
/res/layout/about.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:padding="10dip"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <TextView 
   android:id="@+id/about_content"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="@string/about_text"/>
</ScrollView>
/res/layout/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="wrap_content"
android:orientation="vertical">
<TextView android:layout_width="fill_parent" android:textSize="25sp"
android:layout_height="wrap_content" android:text="@string/main_title" />
<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>
/res/layout-land/main.xml(横屏界面)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="15dip"
>
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:paddingLeft="20dip"
android:paddingRight="20dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_title"
android:gravity="center"
android:layout_marginBottom="20dip"
android:textSize="24.5sp"/>
<TableLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button
android:id="@+id/continue_button"
android:text="@string/continue_label" />
<Button
android:id="@+id/new_button"
android:text="@string/new_game_label"/>
</TableRow>
<TableRow>
<Button
android:id="@+id/about_button"
android:text="@string/about_label"/>
<Button
android:id="@+id/exit_button"
android:text="@string/exit_label"/>
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
/res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Sudoku</string>
<string name="main_title">Android 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.
Starting with a partiallycompleted 9*9 grid, the
objective is to fill the grid so that each
row, each column, and each of the 3*3 boxes
(also called <i>blocks</i>) contains the digits
1 to 9 exactly once.
</string>
</resources>AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.payne.android.SudokuActivity"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".SudokuActivity"
                  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=".About"
         android:label="@string/about_title">
        </activity>
    </application>
</manifest>

解决方案 »

  1.   

    在/res/layout/main.xml里把button的id加上试试
      

  2.   

            View continueButton = findViewById(R.id.continue_button);
            continueButton.setOnClickListener(this);        View newButton = findViewById(R.id.new_button);
            newButton.setOnClickListener(this);        View aboutButton = findViewById(R.id.about_button);
            aboutButton.setOnClickListener(this);        View exitButton = findViewById(R.id.exit_button);
            exitButton.setOnClickListener(this);
            改成:
              Button continueButton = (Button)findViewById(R.id.continue_button);
            continueButton.setOnClickListener(this);        Button newButton = (Button)findViewById(R.id.new_button);
            newButton.setOnClickListener(this);        Button aboutButton = (Button)findViewById(R.id.about_button);
            aboutButton.setOnClickListener(this);        Button exitButton = (Button)findViewById(R.id.exit_button);
            exitButton.setOnClickListener(this);--------------------------------------------------------
            Intent i = new Intent(this, About.class);
            startActivity(i);
            改成:
              Intent i = new Intent(SudokuActivity.this, About.class);
            startActivity(i);
      

  3.   

    可以加上try{}catch()跟踪一下,否则有的情况是跟不出来的
      

  4.   

    你会看LOG不?可以在DDMS的logCat中查看相关出错的信息。