Why am I getting local variable 'timer' not initialized?

60 Views Asked by At

I'm trying to make a quiz app here where on 15 min mark the next button gets disabled, But in the line timer.stop(); I get a message saying that the local variable may not have been initialised. What do I do

Timer timer = new Timer(1000,new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //SimpleDateFormat sdf= new SimpleDateFormat("mm:ss");
            //label.setText(sdf.format(new java.util.Date()));
            label.setText(String.valueOf(sec));
            label.setText(String.valueOf(min));
            
            if(sec == 60)
            {
                sec=0;
                min++;
                if(min==15)
                {
                    timer.stop();
                    btnNext.setEnabled(false);
                }
            }
            sec++;
        }
    });
    timer.start();
0

There are 0 best solutions below