我想通过按钮从这个(KlikomaniaActivity)打开另一个Activity(GameProcess),但是当我点击按钮时程序崩溃。我不是一个专业的android程序员,请说出我有什么错误:
packagecom.makeandroid.klikomania;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
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("com.makeandroid.klikomania.GameProcess");
// эапускаем деятельнсть
startService(intent);
}
});
}
}
并且在这里GameProcess Acticity:
public class GameProcess extends KlikomaniaActivity {
private static int rezult = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gameprocess);
final Button Butklik = (Button)findViewById(R.id.klik);
final TextView TextTime = (TextView)findViewById(R.id.texttime);
final TextView TextKolvo = (TextView)findViewById(R.id.kolvo);
Butklik.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
rezult=rezult+1;
TextKolvo.setText(rezult);
}
});
}
}
答案 0 :(得分:0)
首先确保您将活动添加到清单文件中:
<activity android:name="com.makeandroid.klikomania.GameProcess"></activity>
第二,开始活动使用此代码:
final Intent gameProcessIntent= new Intent(this, GameProcess.class);
Butstart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(gameProcessIntent);
}
});
这应该正常工作