-1

如何通过单击按钮(ButStart)打开 Activity(GameProcess)?

我已经对其进行了编辑并加以体现。你看到了什么错误?当我点击按钮(ButStart)时它崩溃了。

package com.makeandroid.klikomania;

public class KlikomaniaActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final Button Butstart = (Button)findViewById(R.id.butstart);
    final Button Butrez = (Button)findViewById(R.id.butrez);

    Butstart.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(KlikomaniaActivity.this,GameProcess.class); 
             startActivity(intent);
        }
    });
}

}

这是 GameProgress 活动:

package com.makeandroid.klikomania;


public class GameProcess extends Activity {



 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gameprocess);

        }
 }

显现:

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity android:name="com.makeandroid.klikomania.GameProcess"></activity>
    <activity
        android:name="com.makeandroid.klikomania.KlikomaniaActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

</manifest>
4

1 回答 1

1

可能你button Butstartnull。检查您的“butstart”IDmain.xml

于 2012-12-30T21:13:37.213 回答