java - android handler making variable as final -


why message when i'm writing handler , compiler insist on making variable final?

cannot refer non-final variable inside inner class defined in different  method 

my question how can define non-final variable in code: (how can change book, file, note , time non finals) global variables , i'm passing them trakingnotes

public void trakingnotes (final double book, final long file, final string note, final double time) {     maxinfo = 100;     timer updatetimer = new timer("notesaveings");     updatetimer.scheduleatfixedrate(new timertask() {       public void run() {        updategui( book, file, note, time);       }     }, 0, 1000);     }   notesdb dbnotes = new notesdb(this);  private void updategui( final double book, final long file, final string note, final double time) {      long idy;       // update gui      notehandler.post(new runnable() {     public void run() {      long idy;      dbnotes.open();           idy= dbnotes.insertnotetitle (book, file, note, time);      if ((book) == samebook )//samebook global varible      {readdbnotes();}      dbnote.close();   });} 

you have declare book, file, note , time final because use them inside of anonymous inner classes.

i guess don't want them final because want change values. can accomplished using additional final variables. if want change value of book can write this:

public void trakingnotes (double book, final long file, final string note, final double time) {     maxinfo = 100;     timer updatetimer = new timer("notesaveings");     final double changedbook = book + 1.0;      updatetimer.scheduleatfixedrate(new timertask() {       public void run() {        updategui( changedbook, file, note, time);       }     }, 0, 1000); } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -