2013-11-23 12 views
0

錯誤java.lang.NullPointerException異常這是我的Main.java它是圍繞服務器套接字被做成「get().logger().tag();」我在實例中添加了所有這些,我真的不確定它是什麼問題。Java - 我有一個.get()的實例,但它給Server.Main.main(Main.java:18)

public class Main { 

    private Logger LOGGER; 
    private static Main INSTANCE; 

    public static void main(String[] args) throws IOException { 
     try 
     { 
      final int PORT = 43594; 
      ServerSocket server = new ServerSocket(PORT); 
      System.out.println("Waiting for clients to connect..."); 
      get().logger().tag(); //This is the part which gives the error 
      get().logger().log("Starting up" + Settings.Settings.NAME + "..."); 
      //get().init(); 
      while (true) 
      {            
       Socket s = server.accept(); 

       //System.out.println("Client connected from " + s.getLocalAddress().getHostName()); 

       Client chat = new Client(s); 
       Thread t = new Thread(chat); 
       t.start(); 
      } 
     } 
     catch (Exception e) 
     { 
      System.out.println("An error occured."); 
      e.printStackTrace(); 
     } 
    } 

    public Main(int world) { 
     this.LOGGER = new Logger(); 
    } 

    public Main init() { 
     try { 
      long currentTime = Utils.currentTimeMillis(); 
      logger().log("Completed loading in " + (Utils.currentTimeMillis() - currentTime) + " ms."); 

     } catch (Exception e) { 
      logger().error("Unable to start server..."); 
      logger().error(e); 
     } 
     return this; 
    } 

    public Logger logger() { 
     return LOGGER; 
    } 

    public static Main get() { 
     return INSTANCE; 
    } 

} 

我知道這是什麼待辦事項使用get()。但林不知道

任何幫助將幫助很多

感謝,

+1

您忘記創建Main的新實例。 –

回答

1

你並沒有使用任何地方INSTANCE,看到因爲它是private,我猜這也是null

指定INSTANCE = new World(...)

+0

INSTANCE = new World(Integer.parseInt(args [0])); //會是這樣嗎?我不太清楚把什麼放在括號內 – user3025516

+0

我不知道,是'args [0]'你想要什麼?測試它? – slezica

+0

Nope; /不工作 – user3025516

相關問題