• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile Error : cannot find symbol constructor Thread(Runnable)

 
Junghyun Cho
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Would you give me some adivce to solve this compiling error?
Thread class has a constructor which has argument Runnable class.
I can't understand why this happen.

=================================================================
RunnableTest.java:21: cannot find symbol
symbol : constructor Thread(RunnableTest)
location: class java.lang.Thread
new Thread(thread50).start();
^
RunnableTest.java:22: cannot find symbol
symbol : constructor Thread(RunnableTest)
location: class java.lang.Thread
new Thread(thread100).start();
^
2 errors
======================================================
/* RunnableTest.java */
import java.io.*;
class RunnableTest implements Runnable {
long delay;
String message;
RunnableTest(String message, long delay) {
this.message = message;
this.delay = delay;
}
public void run() {
try {
while(true) {
System.out.print(message+ " ");
Thread.sleep(delay);
}
} catch(InterruptedException e){ return; }
}
public static void main(String[] args) {
RunnableTest thread50 = new RunnableTest("t50", 50);
RunnableTest thread100 = new RunnableTest("t100", 100);
new Thread(thread50).start();
new Thread(thread100).start();
}
}
 
amitabh mehra
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compiled fine on my system without any errors. The code seems fine.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's strange. It compiles fine for me. Are you sure you don't have a second copy of RunnableTest.java in your working directory, one that doesn't implement the Runnable interface?
 
Junghyun Cho
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems it's my computer problem. I tried on other PC and it works.

I don't know why but only calling java.lang.Thread costructor make compiling error happen.
Anyone knowing about this?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most likely in your experimentation you created your own class named "Thread" or interface named "Runnable", and either the *.java or *.class files are still around on that machine. Use the Windows "Find File" feature to find Thread.java, Thread.class, Runnable.java and/or Runnable.class, and delete any ones you find that you may have created yourself.
 
Junghyun Cho
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found there was Runnable.class in my classpath directory.
After deleting that file, it works.

Thank you , Ernest and all who replied.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic