java - Cant access methods from another class -


im calling datacomparison()

public class steganographygui {      ...      datacomparison datacomp;     datacomp = new datacomparison();  }  public int getlsb(){     string x = filechooser1.getselectedfile().getabsolutepath();     x = x.substring(x.length() - 10, x.length() - 9);     return integer.parseint(x); } 

when criteria met. problem that, when try access getlsb using gui.getlsb()

public class datacomparison {      public static steganographygui gui;      ...       public datacomparison(){          lsb = gui.getlsb();       }     public static void main(string[] args) {         gui = new steganographygui();         gui.setvisible(true);     } 

error appears - exception in thread "awt-eventqueue-0" java.lang.nullpointerexception

how can fix this?

you trying call getlsb() in datacomparison class, don't give reference of steganographygui class. change following line:

 datacomparison datacomp;  datacomp = new datacomparison(); 

to:

datacomparison datacomp; datacomp = new datacomparison(this); 

and change constructor well:

public datacomparison(steganographygui guiref){     gui = guiref; } 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -