私はアンドロイド開発には新しく、ちょっとしたゲームを作成しようとしています。私の最初のCountDownTimer
はGameView
のサブクラスSurfaceView
にコンストラクタによって作成されています。私は次のレベルに合格するためには何をすべき実行方法の中で新しいCountDownTimerを開始してください
は、CountDownTimer class
のcancel()
を呼び出し、次のレベルのためにすべての要素をreadaptingし、再び新しいCountDownTimer
を作成することです。私はを実装している私のGameView
クラスのrun()
でこれをやっています。
私はオンラインで物事を読んできましたが、ほとんどのソリューションはActivities
を使用していますが、私はSurfaceView
のサブクラスで働いています。
これは私が
E/AndroidRuntime: FATAL EXCEPTION: Thread-4
Process: com.example.lucadigiammarino.biogame, PID: 3569
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:200)
at android.os.Handler.<init>(Handler.java:114)
at android.os.CountDownTimer$1.<init>(CountDownTimer.java:114)
at android.os.CountDownTimer.<init>(CountDownTimer.java:114)
at com.example.lucadigiammarino.biogame.GameCountDownTimer.<init>(GameCountDownTimer.java:0)
at com.example.lucadigiammarino.biogame.GameView.startTimer(GameView.java:135)
at com.example.lucadigiammarino.biogame.GameView.run(GameView.java:306)
at java.lang.Thread.run(Thread.java:761)
が@Romanへ
メインスレッドではなく、UIを扱ういくつかの関数を実行しようとします。 – phnmnn
http://stackoverflow.com/questions/11086129/runonuithread-inside-a-view –