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:
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. 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)
A timeout of zero is interpreted as an infinite timeout.docs.oracle.com/javase/7/docs/api/java/net/…