| Author |
Compile Error : cannot find symbol constructor Thread(Runnable)
|
Junghyun Cho
Greenhorn
Joined: May 22, 2008
Posts: 3
|
|
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
Joined: Dec 05, 2006
Posts: 98
|
|
|
Compiled fine on my system without any errors. The code seems fine.
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
|
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?
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Junghyun Cho
Greenhorn
Joined: May 22, 2008
Posts: 3
|
|
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
Joined: Jul 08, 2003
Posts: 24061
|
|
|
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.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Junghyun Cho
Greenhorn
Joined: May 22, 2008
Posts: 3
|
|
I found there was Runnable.class in my classpath directory. After deleting that file, it works. Thank you , Ernest and all who replied.
|
 |
 |
|
|
subject: Compile Error : cannot find symbol constructor Thread(Runnable)
|
|
|