java - Unable to access parameters inside anonymous inner class on Android -


this question has answer here:

my question deals fundamentals of java. creating android app , access method parameters inside anonymous thread create inside method. somehow, keep getting null pointer exception. here's how code 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 create loop uses "x" , "y" parameters //as "xx"  , "yy", respectively. //keep getting null pointer exception on line attempt  //calculations x , y    }    }).start();   } 

if please have answer great. should make method static? perhaps, rid of final keyword?

thank you

if you're getting null pointer exception means didn't initialize object variable. npe thrown when app wants value calculations hasn't been finished. try make calculations in single thread mode or provide code of calculation.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -