1
ハンドラを作成しているときにこのメッセージが表示され、コンパイラが変数を最終的なものにすることを主張しているのはなぜですか?アンドロイドハンドラが最終変数として
Cannot refer to a non-final variable inside an inner class defined in a different
method
私の質問は、私は私のコードで非final変数を定義する方法です。(どのように私は非決勝にブック、ファイル、ノートや時間を変更することができます)、彼らはグローバル変数であり、私はそれらを渡しています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 the GUI
noteHandler.post(new Runnable() {
public void run() {
long idy;
dbnotes.open();
idy= dbnotes.insertnoteTitle (book, file, note, Time);
if ((book) == samebook)//samebook is a global varible
{ReadDBnotes();}
dbnote.close();
});}
他の方法からの可変書類を渡していますか? – moe