这是我的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()有关。但我不确定
任何帮助都会有很多帮助
谢谢,
答案 0 :(得分:1)
你没有在任何地方分配INSTANCE
,并且看到它是private
,我猜它也是null
。
分配INSTANCE = new World(...)
。