public class androStrategy extends Activity implements OnClickListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Set up click listeners for all the buttons
View game_start = findViewById(R.id.btn_startGame);
game_start.setOnClickListener(this);
View save_exit = findViewById(R.id.btn_SaveExit);
save_exit.setOnClickListener(this);
View aboutButton = findViewById(R.id.btn_Help);
aboutButton.setOnClickListener(this);
}
// ...
public void onClick(View v)
{
switch (v.getId())
{
case R.id.btn_Help:
Intent helpIntent = new Intent(this, about.class);
startActivity(helpIntent);
break;
// More buttons go here (if any) ...
case R.id.btn_startGame:
Intent gameIntent = new Intent (this, Game.class);
startActivity(gameIntent);
break;
case R.id.btn_SaveExit:
finish();
break;
}
}
@Override
public void onPause()
{
super.onPause();
}
@Override
public void onResume()
{
super.onResume();
}
}
なぜコードが停止したのですか? それは前に働いていましたが、私はここで何も変更しませんでした。 コメントをしようとしました Intent gameIntent = new Intent(this、Game.class); startActivity(gameIntent); これが動作するかどうかを確認してください。主な活動の強制終了
Javaのランダムエラーにうんざりです。 これはコーヒーを飲んだ後に機能します。
View game_start = findViewById(R.id.btn_startGame);
ものであり、ボタン場合は、次のようにボタンとしてそれらをキャスト:また
Button game_start = (Button) findViewById(R.id.btn_startGame);
LogCatエラー出力を投稿できますか? –
LogCatを使用している場合は、取得している例外を投稿してください。 – whirlwin
コードがランダムに破られることはありません(重要な作業を行う乱数がない限り)。スタックトレースとは何ですか? – Haphazard