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 call info.load() before.
  • getcircuito() returns null.
  • 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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -