-
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
-
Re: Thread getting NoClassDefFoundError?
Where did you keep your MarqueeCanvas class? Check up your package names and
your runtime paths.
"CJ" <cjboales@yahoo.com> wrote:
>
>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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|