0

当我的游戏显示暂停警报对话框并在一段时间后自动锁定屏幕时,我收到“无法销毁活动(NullPointer)”错误。

我一直在阅读类似的帖子,但我无法让它工作。

这是用户按下后退或菜单按钮时调用的方法:

private void showPauseDialog()
    {
        this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                //Handler mHandler = new Handler(); 
                MadhonActivity.this.mMusic.pause();
                AlertDialog.Builder builder;
                //AlertDialog alertDialog;



                LayoutInflater inflater = (LayoutInflater) MadhonActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE);
                View layout = inflater.inflate(R.layout.pause,(ViewGroup) getCurrentFocus());//findViewById(R.id.layout_root));


                //TextView text = (TextView) layout.findViewById(R.id.stcomplete_score);
                TextView text_0 = (TextView) layout.findViewById(R.id.pause_tv);
                //text.setText("200");
                Typeface font = Typeface.createFromAsset(getAssets(), "font/mvb2.ttf");  
                //text.setTypeface(font);
                text_0.setTypeface(font);


                ImageButton btnext = (ImageButton)layout.findViewById(R.id.pause__btnext);


                builder = new AlertDialog.Builder(MadhonActivity.this);
                builder.setView(layout);


                final AlertDialog alertDialog = builder.create();
                alertDialog.setCancelable(true);

                btnext.setOnClickListener(new OnClickListener(){

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        alertDialog.dismiss();
                        MadhonActivity.this.mMusic.play();
                    }});

                alertDialog.show();


                alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));




            }
        });
    }

这里是我的 onDestroy 方法:

protected void onDestroy()
 {  
     madhon_ko.stop(); //sound
     mMusic.stop(); //sound
     super.onDestroy();

 }

有什么帮助吗?

4

1 回答 1

0

我认为在onClickListener()方法中,您必须调用finish()要关闭的活动的方法。

于 2012-06-23T05:26:27.893 回答