如何通过单击按钮(ButStart)打开活动(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>
答案 0 :(得分:1)
您的button Butstart
可能是null
。检查main.xml