Here you have a non-local variable ( https://en.wikipedia.org/wiki/Non-local_variable ), that is, you get access to the local variable in the method of the anonymous class.
The local variables of the method are stored on the stack and are lost as soon as the method ends, however, even after the method finishes, the local object of the inner class is still alive on the heap and it will need to access this variable (here, when the action is executed).
I would suggest two workarounds: Either you create your own class that implements the actionlistenner and takes your variable as a constructor argument and saves it as an attribute of the class. Therefore, you should only access this variable inside the same object.
Or (and this is probably the best solution) just qualify a copy of the final variable to access it in the inner scope, since the error involves making it permanent:
This will suit your case since you are not changing the value of the variable.
source share