Intermittent ClassNotFoundException & Basic Debug Interpretation.
in
Programming Questions
•
2 years ago
I modified someone's clock sketch (sorry, the source doesn't mention authorship and I forgot where I found it) to be a class (one of the recommended ways to learn about classes is to covert sketches to classes). I've noticed that maybe 30% of the time I launch my app containing this class, that I get a ClassNotFoundException with this or one of several other classes used in the sketch.
So first, as a general issue, what can cause a sketch to generate class not found exceptions on an intermittent basis -- sometimes the sketch runs fine and other times it acts as if a class were not defined or present in the sketch?
Second, what do the numbers at the end of each line in a debug window mean? I thought they were line numbers, but, if they are, they are useless in the processing.org editor if a sketch has multiple separate files organized as tabs because the line numbers count all the lines in the sketch sequentially, but, when looking at a sketch in the processing editor, the code in each tab begins with 1.
Here's what I get when it can't find a class:
processing.app.debug.RunnerException: ClassNotFoundException: Feed_Reader$Clock
at processing.app.Sketch.placeException(Sketch.java:1543)
at processing.app.debug.Runner.findException(Runner.java:582)
at processing.app.debug.Runner.reportException(Runner.java:558)
at processing.app.debug.Runner.exception(Runner.java:498)
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
at processing.app.debug.EventThread.run(EventThread.java:89)
processing.app.debug.RunnerException: ClassNotFoundException: Feed_Reader$Clock
at processing.app.Sketch.placeException(Sketch.java:1543)
at processing.app.debug.Runner.findException(Runner.java:582)
at processing.app.debug.Runner.reportException(Runner.java:558)
at processing.app.debug.Runner.exception(Runner.java:498)
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
at processing.app.debug.EventThread.run(EventThread.java:89)
Exception in thread "Animation Thread" java.lang.NoClassDefFoundError: Feed_Reader$Clock
at Feed_Reader.setup(Feed_Reader.java:111)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: Feed_Reader$Clock
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 4 more
Here's the block of code in my main sketch's setup() where I call some of the separate classes used in the sketch; note myClock on line 3:
Sometimes the classnotfoundexception occurs for one of the other classes and I don't think it's caused by a bug in a particular class, but, for example, here's the myClock class being called:
So first, as a general issue, what can cause a sketch to generate class not found exceptions on an intermittent basis -- sometimes the sketch runs fine and other times it acts as if a class were not defined or present in the sketch?
Second, what do the numbers at the end of each line in a debug window mean? I thought they were line numbers, but, if they are, they are useless in the processing.org editor if a sketch has multiple separate files organized as tabs because the line numbers count all the lines in the sketch sequentially, but, when looking at a sketch in the processing editor, the code in each tab begins with 1.
Here's what I get when it can't find a class:
processing.app.debug.RunnerException: ClassNotFoundException: Feed_Reader$Clock
at processing.app.Sketch.placeException(Sketch.java:1543)
at processing.app.debug.Runner.findException(Runner.java:582)
at processing.app.debug.Runner.reportException(Runner.java:558)
at processing.app.debug.Runner.exception(Runner.java:498)
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
at processing.app.debug.EventThread.run(EventThread.java:89)
processing.app.debug.RunnerException: ClassNotFoundException: Feed_Reader$Clock
at processing.app.Sketch.placeException(Sketch.java:1543)
at processing.app.debug.Runner.findException(Runner.java:582)
at processing.app.debug.Runner.reportException(Runner.java:558)
at processing.app.debug.Runner.exception(Runner.java:498)
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
at processing.app.debug.EventThread.run(EventThread.java:89)
Exception in thread "Animation Thread" java.lang.NoClassDefFoundError: Feed_Reader$Clock
at Feed_Reader.setup(Feed_Reader.java:111)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: Feed_Reader$Clock
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 4 more
Here's the block of code in my main sketch's setup() where I call some of the separate classes used in the sketch; note myClock on line 3:
- myMoonImage = new MoonImage(width-((width/4))+60,(height/2),#3FB748,255);
- myRadarImage = new RadarImage(260,50,#3FB748,255);
- myClock = new Clock(width-((width/4))+60,(height/2),105);
- myTrafficCams = new TrafficCams(width-((width/2))+45,(height/2)+13,172,128,255,255,4);
- myWeather = new Weather(260,65,#3FB748);
- myWaves = new Waves(4,100,#3FB748);
- myTides = new Tides(12,134,#3FB748,60);
Sometimes the classnotfoundexception occurs for one of the other classes and I don't think it's caused by a bug in a particular class, but, for example, here's the myClock class being called:
- public class Clock {
- float d, mm, wCen, hCen, Cir, CirR1, CirR2, CirR3;
- String f;
- PFont b;
- Clock(int _wCen, int _hCen, int _Cir){
- wCen = _wCen;
- hCen = _hCen;
- Cir = _Cir;
- b = loadFont ("Andalus-48.vlw");
- }
- public void display() {
- smooth();
- stroke(255);
- fill(130);
- textFont(b,32);
- int d = day();
- int mm = month();
- int yy = year()-2000;
- String f = nf(mm,2) + "." + nf(d,2) + "." + str(yy); //nf(yy,4);
- text(f,wCen-55, hCen+65);
- // time
- // wCen = width-((width/4)+50);
- // hCen = height/2;
- //Cir = 150;
- CirR1 = Cir/3;
- CirR2 = Cir/2.5;
- CirR3 = Cir/4;
- fill(200);
- float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
- float m = map(minute(), 0, 60, 0, TWO_PI) - HALF_PI;
- float h = map(hour()% 12, 0, 12,0, TWO_PI) - HALF_PI;
- stroke(194);
- ellipse(wCen, hCen, 6, 6);
- strokeWeight(1);
- line(wCen, hCen, cos(s) * CirR1 + wCen, sin(s) * CirR1 + hCen);
- strokeWeight(2);
- line(wCen, hCen, cos(m) * CirR2 + wCen, sin(m) * CirR1 + hCen);
- strokeWeight(3.5);
- line(wCen, hCen, cos(h) * CirR3 + wCen, sin(h) * CirR1 + hCen);
- }
- }
1