錯誤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()。但林不知道
任何幫助將幫助很多
感謝,
您忘記創建Main的新實例。 –