|
-
Thread getting NoClassDefFoundError?
OK, I'm trying to learn this thread stuff and ran into a little problem. I
don't know if it is my understanding, code, or a combination.
Here is what is going on....
I have an applet that runs fine. I wanted to add a thread to that applet
to run a marquee across the bottom (South). I set up a MarqueeCanvas class
to hold the message, then added a thread to start the marquee running. I
instantiate the Canvas first in the applet. Then instantiate the thread passing
in the Canvas object. In the Thread code I instantiate a canvas object as
well, and copy the object passed in into this instance (so that I don't loose
the object)....then when I get back to the applet I "start" the thread, but
I get the famous NoClassDefFoundError:MarqueeCanvas. I don't understand.
I thought that Java passed by reference and if I created an object in my
applet and then passed that object to my Thread - my thread should then have
the address of the object and be able to reference it, right?
here are snippits of the code:
Applet code - (dots indicate missing code)
...
MarqueeCanvas marqueeCanvas = new MarqueeCanvas(
"Welcome to My Movie Rater! Hope you enjoy!!!");
MarqueeThread marqueeThread = new MarqueeThread(marqueeCanvas);
public void init (){
...
getContentPane().add("South", marqueeCanvas);
System.out.println("Starting Marquee Thread!");
marqueeThread.start();
setMovieVector("general.movies");
...
}
MarqueeCanvas code -
public class MarqueeCanvas extends Canvas{
...
public MarqueeCanvas (String s) {
message = s;
System.out.println("message = " + message);
}
public void decrementPosition() {
if (position + messageWidth < 0){
position = initialPosition;
}
else
{
position = position - delta;
}
repaint();
}
...
}
MarqueeThread -
import java.lang.*;
import java.io.*;
public class MarqueeThread extends Thread{
MarqueeCanvas canvas;
public MarqueeThread (MarqueeCanvas c) {
canvas = c;
System.out.println("Marquee Canvas created in Marquee Thread!");
}
public void run(){
while (true){
canvas.decrementPosition();
try{
sleep(200);
}
catch (InterruptedException e) {
return;
}}}}
Any ideas? I'm really stumped and need help to get this working please?
TIA,
cj
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