-2

I am trying to use timer in simple Android app,but as long as I use this code...

public void controlTimer () {
    CountDownTimer = new CountDownTimer(10000,1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            Log.i("tick", "tock");
        }

        @Override
        public void onFinish() {

        }
    } start();

...the app ceases to work saying

Error:(42, 10) error: ';' expected

I have done loads of searching and now I am desperate. What is wrong in the code?

Many thanks! Jan.

1 Answers1

2

You forgot the '.' and also forgot to name the variable to which you are assigning the anonymous class instance though you don't need to assign it at all in this case.

public void controlTimer () {
    CountDownTimer tmp = new CountDownTimer(10000,1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            Log.i("tick", "tock");
        }

        @Override
        public void onFinish() {

        }
    };
    tmp.start();
}

or you could do it like :

public void controlTimer () {
        new CountDownTimer(10000,1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                Log.i("tick", "tock");
            }

            @Override
            public void onFinish() {

            }
        }.start();
    }
MS Srikkanth
  • 3,829
  • 3
  • 19
  • 33