0
我正在實現有趣的遊戲倒數計時器。我想在完成一分鐘後顯示自定義對話框。我試過,當運行應用程序它運行正常,但我得到了像FATAL EXCEPTION的異常。我嘗試了很多,每次都會遇到異常。在Android中完成count_downtimer時顯示自定義對話框消息
這是我在我的活動中倒數計時器的代碼。
new CountDownTimer(60*1*1000, 1000)
{
@Override
public void onTick(long millisUntilFinished)
{
textView_TimerValue.setText("seconds remaining : "
+ millisUntilFinished/1000);
}
@Override
public void onFinish()
{
textView_TimerValue.setText("TIME IS OVER");
//tell the Dialog to use the dialog.xml as it's layout description
dialog = new Dialog(Gsk_Demo.this);
dialog.setContentView(R.layout.dialogbox_);
TextView txt = (TextView) dialog.findViewById(R.id.textV);
txt.setText("Your Time Is Over.Click Next.");
Button dialogButton1 = (Button) dialog.findViewById(R.id.buttonDialog_Next);
dialogButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(Gsk_Demo.this , Code_Demo.class);
startActivity(i);
}
});
dialog.show();
}
}.start();
這裏是我的日誌貓堆棧跟蹤。
11-20 15:22:44.158: E/AndroidRuntime(1211): FATAL EXCEPTION: main
11-20 15:22:44.158: E/AndroidRuntime(1211): android.view.WindowManager$BadTokenException: Unable to add window -- token [email protected] is not valid; is your activity running?
11-20 15:22:44.158: E/AndroidRuntime(1211): at android.view.ViewRoot.setView(ViewRoot.java:527)
11-20 15:22:44.158: E/AndroidRuntime(1211): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
11-20 15:22:44.158: E/AndroidRuntime(1211): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
11-20 15:22:44.158: E/AndroidRuntime(1211): at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-20 15:22:44.158: E/AndroidRuntime(1211): at android.app.Dialog.show(Dialog.java:241)
11-20 15:22:44.158: E/AndroidRuntime(1211): at com.gsk.Gsk_Demo$1.onFinish(Gsk_Demo.java:124)
11-20 15:22:44.158: E/AndroidRuntime(1211): at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118)
11-20 15:22:44.158: E/AndroidRuntime(1211): at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 15:22:44.158: E/AndroidRuntime(1211): at android.os.Looper.loop(Looper.java:123)
11-20 15:22:44.158: E/AndroidRuntime(1211): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-20 15:22:44.158: E/AndroidRuntime(1211): at java.lang.reflect.Method.invokeNative(Native Method)
11-20 15:22:44.158: E/AndroidRuntime(1211): at java.lang.reflect.Method.invoke(Method.java:507)
11-20 15:22:44.158: E/AndroidRuntime(1211): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-20 15:22:44.158: E/AndroidRuntime(1211): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-20 15:22:44.158: E/AndroidRuntime(1211): at dalvik.system.NativeStart.main(Native Method)
感謝您的help.You是great.My代碼working.Now不顯示任何exceptions.Thanks。 – tazeenmulani
歡迎您 –
對不起,我還是有同樣的例外。 – tazeenmulani