So this is my code:
ServerSocket server = new ServerSocket(port);
Socket sock = new server.accept();
It says “server cannot be resolved to a type”.
Well as you can see, I made a variable called “server”. How can I use server.accept()?
Oh, and I tried Socket sock = new this.server.accept(); and Socket sock = new accept(); and Socket sock = new this.accept(); but none of them work.
Are you trying to create a new object or call a method on an existing one? If you just want to use
server.accept(), you need to remove thenewbefore the method call:The
newkeyword is only used when you want to instantiate a type. Once you have an instance of that type, you never need to use thenewagain and can just call methods on it by using the variable containing that instance.Currently the compiler is trying to use
serveras a type, which is why you’re getting an error complaining about it not being resolved to one. 😀