Local Variable Must be Final Java Error -


i want update variable every time click on jlabel. however, error because variable not declared locally.

timer pictimer = new timer(1000, new actionlistener(){              int oldrr=0;             int oldrc=0 ;             @override             public void actionperformed(actionevent e) {                 arraywm[oldrr][oldrc].seticon(null);                 random random = new random();                 arraywm[oldrr][oldrc].seticon(null);                 int rr = random.nextint(3 - 0 + 1) + 0;                 int rc = random.nextint(3 - 0 + 1) + 0;                 oldrr = rr;                 oldrc = rc;                 arraywm[rr][rc].seticon(new imageicon("img/one.jpg"));                 int score=0;                  arraywm[rr][rc].addmouselistener(new mouseadapter(){                      @override public void mouseclicked(    mouseevent e){                         score++;                         lbltimer.settext(string.valueof(score));                        }                     }                   );             }         }); 

change this

final int[] score = {0}; 

and

score[0]++; 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -