调用另一个类失败了

时间:2013-02-01 09:45:42

标签: android class alertdialog

当用户想要退出时,会弹出一个对话框,确定,游戏将退出。我的代码不会调用另一个类。

private void giveup(){
    Context mcontext=this;      
    final AlertDialog.Builder alert = new AlertDialog.Builder(
                  mcontext);

    alert.setTitle("Are you sure to give up?");
    alert.setNegativeButton("Cancel",
        new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog,
                  int which) {
                  click.start();   
                  dialog.cancel();                                            

              } });
        alert.setPositiveButton("OK",
              new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog,
                           int which) {
                       click.start();                                           
                       dialog.cancel();
                       try{
                           Class<?> ourClass = Class.forName("com.ithinkDictionary.Gameover");
                           Intent ourIntent = new Intent(Playing.this, ourClass);
                           startActivity(ourIntent);
                       }catch(ClassNotFoundException e){
                            e.printStackTrace();
                  }
              } 
        });
        alert.show();   
    }
}           

1 个答案:

答案 0 :(得分:3)

你应该使用

Intent ourIntent = new Intent(Playing.this, Gameover.class);
                            startActivity(ourIntent);

假设Play和Gameover都是活动。