[英]java.lang.NullPointerException at ServerSocker.accept()
I am getting the following exception: 我收到以下异常:
java.lang.NullPointerException at
gr.test.asterisk.AsteriskServerSocket.run(AsteriskServerSocket.java:72)
Here's my code: 这是我的代码:
public class AsteriskServerSocket extends Thread{
private Socket server = null;
private ServerSocket serverSocket = null;
private String serverPortString = null;
public AsteriskServerSocket(){
serverPortString = "50050";
try {
serverSocket = new ServerSocket(Integer.parseInt(serverPortString));
serverSocket.setSoTimeout(1000000000);
} catch (SocketTimeoutException s) {
WriteExceptions.writeToFile(s);
} catch (IOException e) {
WriteExceptions.writeToFile(e);
}
}
public void run() {
while (true) {
try {
server = serverSocket.accept();<---- This is the line which I get the exception
......
}
} catch (SocketTimeoutException s) {
System.err.println("Σφάλμα στην Server run. Socket timed out. \n" + s);
break;
} catch (IOException e) {
System.err.println("Σφάλμα στην Server run.\n" + e);
break;
}
}
}
}
And AsteriskServerSocket, I call it in the Main Class: 还有AsteriskServerSocket,我在Main Class中称它为:
public static void main(String[] args) {
AsteriskServerSocket aSS = new AsteriskServerSocket();
}
My Operating System is CentOS release 5.10 (Final) and my JDK version is 1.8.0_45. 我的操作系统是CentOS版本5.10(最终版),我的JDK版本是1.8.0_45。 I don't know why this exception is thrown. 我不知道为什么会抛出该异常。 Am I missing something here? 我在这里想念什么吗?
My exceptions in the constructor is: 我在构造函数中的例外是:
My exception in the constructor is 0 :java.net.BindException: Address already in use at java.net.PlainSocketImpl.socketBind(Native Method) at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:382) at java.net.ServerSocket.bind(ServerSocket.java:375) at java.net.ServerSocket.(ServerSocket.java:237) at java.net.ServerSocket.(ServerSocket.java:128) 我在构造函数中的异常是0:java.net.BindException:java.net.java.net.PlainSocketImpl.socketBind(本机方法)处的地址已在java.net处使用。 java.net.ServerSocket上的ServerSocket.bind(ServerSocket.java:375).java.net.ServerSocket上的ServerSocket.java:237)(ServerSocket.java:128)
You are ignoring exceptions in the constructor and writing them to the logs, therefore serverSocket is null. 您将忽略构造函数中的异常并将其写入日志,因此serverSocket为null。 Check the logs and/or rethrow those exceptions. 检查日志和/或重新抛出那些异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.