5 Replies Latest reply: Feb 19, 2007 8:33 AM by 807606 RSS

    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
      private static MyPlatform myplatform;
           public static void main (String args[]){
                //crea piattaforma
                myplatform=new MyPlatform();
           public synchronized static 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") :

      protected static MyPlatform platf;
      public Initiator() {
                     if(Main.getMyPlatform()==null)throw new Exception("PLATFORM NOT FOUND");
                }catch(Exception e ){
      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!!