gpt4 book ai didi

Java - 我有一个 .get() 实例,但它在 Server.Main.main(Main.java :18)) 处给出错误 java.lang.NullPointerException

转载 作者:行者123 更新时间:2023-12-01 13:48:25 30 4
gpt4 key购买 nike

这是我的 Main.java,它位于服务器套接字“get().logger().tag();”之后的部分我已经在实例中添加了所有这些,我真的不确定它出了什么问题。

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() 相关的事情。但我不确定

任何帮助都会有很大帮助

谢谢

最佳答案

您没有在任何地方分配INSTANCE,而且由于它是私有(private),我猜它也是null

分配INSTANCE = new World(...)

关于Java - 我有一个 .get() 实例,但它在 Server.Main.main(Main.java :18)) 处给出错误 java.lang.NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20165723/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com