I'm not sure why Eclipse is giving me this error:
The method
listen()
is undefined for the typeObject
What simple mistake am I making? Also, is my code the right way to write a main
method which instantiates an EchoServer0
object and calls its listen
method?
public class EchoServer0 {
public void listen() {
ServerSocket socket = null;
try{
socket = new ServerSocket(2013);
System.out.println("Opened server socket");
socket.setSoTimeout(2000);
socket.accept();
socket.close();
}
catch (SocketTimeoutException ste){
System.out.println("Timed out after " + 2000 + " ms");
}
catch (Exception e){
System.out.println(e.getClass().getName()+" at server: " + e.getMessage());
}
}
public static void main(String[] args) {
Object EchoServer0;
EchoServer0.listen();
}
}
Change your main to:
public static void main(String[] args) {
EchoServer echoServer = new EchoServer();
echoServer.listen();
}
When you declare Object EchoServer0;
you have a few mistakes.
new
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With