I am trying to make a program in java the accepts any connection but I getting this error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from void to Thread
at ojas.gome.Server.<init>(Server.java:37)
at ojas.gome.Server.main(Server.java:12)
This piece of code gives me this error:
clientaccepter = new Thread(new Runnable() {
public void run() {
while(true) {
try {
server.accept();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}, "clientaccepter").run();
Please tell me if I left out anything needed.
You're setting a variable equal to the result of the run
method which does not return a value - it's void
.
clientaccepter = new Thread....run();
You should declare the thread and then start it on a separate line if you need to retain a reference to it. Also, you should use start
to begin a new Thread
not run
. Please see Defining and Starting a Thread. Lastly, variables should be camel case starting with lowercase - please see Java Naming Conventions.
clientAccepter = new Thread(...);
clientAccepter.start();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments