-
Thread error
I keep getting an error with the thread constructor in java. Here's the basic of what I have in the 'faulty' program.
import java.awt.*;
import java.net.*;
import java.applet.*
public class WordSearch extends Applet{
Thread th;
public void init() {
}
public void start(){
th = new Thread (this);
th.start();
}
public void run(){
}
public void paint(Graphics g){
}
}
and....for some odd reason...here is the error I get.
WordSearch/WordSearch.java [13:1] cannot resolve symbol
symbol : constructor Thread (WordSearch)
location: class java.lang.Thread
th = new Thread (this);
^
1 error
Errors compiling WordSearch.
Does anyone know why its doing this? A similar error I've had before, without changing anything, had something to do with APIs and compiling with -deprecation.
-
the Thread class cannot take an object of type WordSearch into any of its constructors... It's an oddly-worded error message, but it is not an odd message.
Thread has a constructor that takes Runnable objects, and to PROVE to the compiler that your WordSearch is capable if behaving like a Runnable, it MUST "implements Runnable"
Runnable mandates that a run() method be provided, which you have indeed done.. but it isnt enough that you just write void run(){}.. See what i mean?
|Its a bit like being pulled over by a cop, and he says "show me your license" and you say "well i dont have it with me but i can drive, obviously, because im sitting in the car, piloting it down the road"
and ihe's like "i dont care, if you dont have your license, i cannot accept anything else as proof that you can drive a car"
the compiler is saying "if you cannot implements Runnable, i cannot accept anything else as proof that this object is capable of existing in its own thread..
-
hope that helps..
-
yeah, thanks!
I just added the 'implements Runnable', which I accidently overlooked when copying elements from a program, and it stopped the error and run.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks