DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3

Thread: Thread error

  1. #1
    Join Date
    Mar 2003
    Posts
    9

    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.

  2. #2
    Join Date
    Feb 2004
    Posts
    808
    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..
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

  3. #3
    Join Date
    Mar 2003
    Posts
    9
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links