Calling Main Class method returns NullPointer
Hi guys,
I'm working on a multi-files project in Java. This should be run from the main method of "Main.java" class (no command line parameters needed). This class creates a new instance of a "Platform" object (succesfully!!) .
Then the class has a get method which should return the same as above "Platform" object..
Here is the code of the main
privatestatic MyPlatform myplatform;
publicstaticvoid main (String args[]){
//crea piattaforma
myplatform=new MyPlatform();
}
publicsynchronizedstatic MyPlatform getMyPlatform(){
return myplatform;
}
}
The get method is called from another class in the SAME PACKAGE,
but I keep on getting NULLPOINTER EXCEPTION when I call this method...
Code of the other class ("Initiator") :
protectedstatic MyPlatform platf;
public Initiator(){
try{
platf=Main.getMyPlatform();
if(Main.getMyPlatform()==null)thrownew Exception("PLATFORM NOT FOUND");
}catch(Exception e ){
System.out.println("Warn");
e.printStackTrace();
}
}
platf is always null : It works only when I add at the beginning of the second class : Main.main(null); so when I create a new Instance of the main class....
but I shouldn't....
Moreover I can't change the code structure...
Anybody knows how to solve this problem?
Thanks a lot!!
Bye

