Hey I have this very weird bug that is probably related to my java version.
Here's my class:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class ClientThread extends Thread{
private Socket clientSocket;
ClientThread(Socket clientSocket) {
this.clientSocket = clientSocket;
}
public void run() {
try {
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String message;
while (((message = in.readLine()) != null)) {
// out.println(message);
System.out.println(message);
}
} catch (IOException e) {
}
}
public Socket getClientSocket() {
return clientSocket;
}
public void setClientSocket(final Socket clientSocket) {
this.clientSocket = clientSocket;
}
}
Here's my java version:
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)
When I compile the class I get the following error:
ClientThread.java:11: error: constructor Thread in class Thread cannot be applied to given types;
ClientThread(Socket clientSocket) {
^
required: Socket
found: no arguments
reason: actual and formal argument lists differ in length
1 error
This error is very weird and I don't understand it. I found pretty much the exact same class on tutorial on the internet. I'm guessing that I have wrong version of java or something. My OS is ubuntu.
It sounds like you had a Thread
class in the default package - potentially just the class file, rather than the source file. java.lang.*
is imported automatically, and all the rest of your imports are single-class imports, so that's the only thing I can see that could have been going on.
You should look at the directory where you're compiling, and make sure that it only has the classes you expect it to... if you're rebuilding, you could just delete all the class files first, and then you know that only the source files are going to be relevant.
While you could keep extending java.lang.Thread
explicitly, it would be much better to find the rogue Thread
class and delete it.
See more on this question at Stackoverflow