My question deals with the fundamentals of JAVA. I am creating an Android app and would like to access method parameters inside an anonymous thread that I create inside the method. Somehow, I keep getting null pointer exception. Here's how my code is looking like:
public void myMethod(final float x, final float y){
new Thread(new Runnable(){
float xx = x;
float yy = y;
@Override
public void run(){
//inside run method I create a for loop that uses the "x" and "y" parameters
//as "xx" and "yy", respectively.
//keep getting null pointer exception on line where i attempt to do
//calculations with x and y
}
}).start();
}
If anyone could please have a an answer it would be great. Should I make the method static? Perhaps, get rid of the final keyword?
thank you