Java Reference
In-Depth Information
Exception occurred: java.lang.NullPointerException (uncaught)
"thread=AWT-EventQueue-0", java.awt.EventDispatchThread.run(),
line=156 bci=152
AWT-EventQueue-0[1] where
[1] java.awt.EventDispatchThread.run (EventDispatchThread.java:156)
This exception has percolated all the way up to the top of the AWT event thread, and
jdb doesn't give you an easy way to see where it was originally thrown. You can ask it to
stop the application when this sort of exception occurs again, like so:
AWT-EventQueue-0[1] catch java.lang.NullPointerException
Set all java.lang.NullPointerException
AWT-EventQueue-0[1] resume
All threads resumed.
Keep resuming the program until you see a long exception stack trace appear on the
jdb console. This isn't a new exception: it's the AWT thread printing out the original
uncaught exception. The top of the exception stack confirms that it was caused by
your faulty code inside DefaultShape , which you know is contained inside the paint
frame bundle. Notice that jdb doesn't give you a way to correlate the exception loca-
tion with a particular JAR file.
What if you didn't know which bundle contained this package? You could try to
locate it using the console, but most framework consoles only let you see exported
packages. For internal packages, you would have to come up with a list of candidate
bundles by manually checking the content of each bundle and comparing the excep-
tion location with the appropriate source. As you'll see in a moment, tracking a prob-
lem to a specific bundle is much easier when you use an OSG i-aware debugger, such as
the Eclipse debugger.
Returning to the broken example, try to paint another shape. Jdb now detects and
reports the exception at the point at which it's thrown inside setColor() . But because
you haven't attached any source files, it doesn't show you the surrounding Java code:
Exception occurred: java.lang.NullPointerException
(to be caught at: javax.swing.JComponent.paint(), line=1,043 bci=351)
"thread=AWT-EventQueue-0", org.foo.paint.DefaultShape.setColor(),
line=126 bci=5
AWT-EventQueue-0[1] list
Source file not found: DefaultShape.java
No problem—you need to attach your local source directory:
AWT-EventQueue-0[1] use org.foo.paint/src
AWT-EventQueue-0[1] list
122 g2.drawImage(m_icon.getImage(), 0, 0, null);
123 }
124
125 public void setColor(Color color) {
126 => m_shape.setColor(color);
127 }
128 }
Search WWH ::




Custom Search