IllegalStateException onFinish CountDownTimer

时间:2017-09-27 10:06:27

标签: java android handler countdowntimer

我遇到以下崩溃消息:

java.lang.IllegalStateException: 
at development.nk.tria.PlayMultit.v (Unknown Source)
at development.nk.tria.PlayMultit.a (Unknown Source)
at development.nk.tria.PlayMultit$a.onFinish (Unknown Source)
at android.os.CountDownTimer$1.handleMessage (CountDownTimer.java:118)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:146)
at android.app.ActivityThread.main (ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative (Native Method)
at java.lang.reflect.Method.invoke (Method.java:515)  
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1283)  
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1099)  
at dalvik.system.NativeStart.main (Native Method)

我的代码如下:

 public class MyCountDownTimer extends CountDownTimer {
        MyCountDownTimer(long sTime, long interval) {
        super(sTime, interval);
    }

    @Override
    public void onFinish() {
        time.setText(R.string.done);
        progressBar.setProgress((int)sTime/100);
        score=0;
        scoreTwoGames=0;
        numGames=0;
        success=false;
        yourscore.setText("");
        showFinishDialog();
    }

    @Override
    public void onTick(long millisUntilFinished) {
    ....
    ....
    }
}

showFinishDialog()方法如下:

private void showFinishDialog() {
    final Handler handler  = new Handler();
    final Runnable runnable = new Runnable() {
        @Override
        public void run() {
            if (fdSuccess!=null &&  fdSuccess.getDialog()!=null && fdSuccess.getDialog().isShowing()) {
                fdSuccess.dismiss();
            }
        }
    };

    if(success && gameCode==1) { fdSuccess.show(fm, "frag_success");
    } else if (success && gameCode==2 && numGames==1) {
        fdSuccess.show(fm, "frag_success");
        handler.postDelayed(runnable, 1000);
    } else if (success && gameCode==2 && numGames==3){
        fdSuccess.show(fm, "frag_success");
    } else if (!success){ fdFailure.show(fm, "frag_failure");
    } else if (success && gameCode==0) {fdSuccess.show(fm, "frag_success");
    }
    result.setText(finishMessage);
    if(countDownTimer!=null) {countDownTimer.cancel();}
}

您认为导致崩溃的问题在哪里? 程序在onFinish或showFininshDialog()方法内崩溃?

0 个答案:

没有答案