Java Exception in thread '"AWT-EventQueue-0"' java.lang.NullPointerException -
i've got class called info , it's method load contains piece code:
circuito[] circuito=new circuito[19]; for(int i=0;i<circuito.length;i++) circuito[i] = new circuito(nome,immpath,sfondopath,previsioni,giri,tempogiro,carico); i pass correctly parameters (i printed tostring() method check if works). then, in class called new have code:
info info=new info(); info.load(); system.out.println(info.getcircuito()[0].tostring()); (the class info contains method getcircuito returns entire array).
then, receive error:
exception in thread "awt-eventqueue-0" java.lang.nullpointerexception @ new.<init>(new.java:21) the line 21 system.out.print line.
i don't understand problem...thank help!
the 3 possibilities npe in line
system.out.println(info.getcircuito()[0].tostring()); are:
- info
null. not possible because callinfo.load()before. getcircuito()returnsnull.getcircuito()[0]null.
that's it. in case code load() shown getcircuito() returning null.
edit: found reason. calling
circuito[] circuito=new circuito[19]; in load() method. therefore assigning new array not class variable new variable in local scope gone again after load() method. change said line to
circuito=new circuito[19]; and should fine.
Comments
Post a Comment