0

I have error as in title connected with following code: Can anybody help me with fix it? I will be very grateful.

    final Sprite mPocisk = new Sprite(0, 0,this.mPocisk, getVertexBufferObjectManager());
    scene.attachChild(mPocisk);
    mPocisk.setVisible(false);
    final Katapulta S_katapulta_wystrzelona = new Katapulta(10, 300, this.mKatapulta_wystrzelona, getVertexBufferObjectManager());
    final Katapulta S_katapulta_zaladowana = new Katapulta(10, 300, this.mKatapulta_zaladowana, getVertexBufferObjectManager()){
        @Override
        public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            setVisible(false);
            S_katapulta_wystrzelona.setVisible(true);
            double time = rzut.t;
// I think following code generate error
                 new CountDownTimer((long) (time*100), 500) {
                     public void onTick(long millisUntilFinished) {
                        double time_copy=+0.5; 
                        System.out.println("test");
                        mPocisk.setPosition((float)rzut.getXfor(time_copy), (float)rzut.getYfor(time_copy));
                        mPocisk.setVisible(true); 
                     }
                     public void onFinish() {
                     }
                  }.start();
            return true;
        }
    };
Blackchart
  • 135
  • 1
  • 3
  • 13
  • meybe somebody could help me? – Blackchart Dec 04 '13 at 10:12
  • it's a matter of being in the proper thread - see this question for some ideas on how to deal with this - http://stackoverflow.com/questions/9849741/toasts-in-andengine-scenes – jmroyalty Dec 04 '13 at 11:13
  • or better, see @Ved Prakash answer in this thread - http://stackoverflow.com/questions/3875184/cant-create-handler-inside-thread-that-has-not-called-looper-prepare. All these answers deal with Toast, but the same principles apply regardless of the type of worker thread. – jmroyalty Dec 04 '13 at 11:20

1 Answers1

0

I solve this problem in the following way

engine.registerUpdateHandler( new TimerHandler(1.0f, new ITimerCallback()
    {

        @Override
        public void onTimePassed(final TimerHandler pTimerHandler)
        {
            //Your task
        }
     }));
BeingMIAkashs
  • 1,375
  • 11
  • 18