我的问题涉及 JAVA 的基础知识。我正在创建一个 Android 应用程序,并希望在我在方法中创建的匿名线程中访问方法参数。不知何故,我不断收到空指针异常。这是我的代码的样子:
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();
}
如果有人能请一个答案,那就太好了。我应该使方法静态吗?也许,摆脱 final 关键字?
谢谢你