[英]What causes a NullPointerException in the AWT-EventQueue-0 thread
I'm trying to do something to track down the problem, but there's not much I can do until paintContents, and everything there looks good through my debugger, but I'll double check to make sure I didn't miss anything. 我正在尝试做一些事情来查找问题,但是直到paintContents为止,我无能为力,而且调试器中的所有东西看起来都很不错,但是我会仔细检查以确保没有遗漏任何东西。 At the very least, I would like to know how to silently handle these (such as catching them and being able to output a meaningful error message, since once it's thrown, the GUI stutters and freezes for a bit). 至少,我想知道如何静默处理这些错误(例如捕获它们并能够输出有意义的错误消息,因为一旦抛出该错误,GUI就会停顿并冻结一段时间)。
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.java2d.pipe.DuctusShapeRenderer.renderPath(Unknown Source)
at sun.java2d.pipe.DuctusShapeRenderer.draw(Unknown Source)
at sun.java2d.pipe.PixelToParallelogramConverter.draw(Unknown Source)
at sun.java2d.pipe.PixelToParallelogramConverter.draw(Unknown Source)
at sun.java2d.SunGraphics2D.draw(Unknown Source)
SNIP - MY CALL TO PAINT THE LAYER
at com.jhlabs.map.layer.Layer.paintContents(Layer.java:70)
at com.jhlabs.map.layer.Layer.paint(Layer.java:59)
at com.jhlabs.map.layer.Layer.paintLayers(Layer.java:76)
at com.jhlabs.map.layer.Layer.paintContents(Layer.java:68)
at com.jhlabs.map.layer.Layer.paint(Layer.java:59)
at com.jhlabs.Globe.paint(Globe.java:305)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknow
n Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
The following source code is from the Java Map Projection Library . 以下源代码来自Java Map Projection Library 。
Layer.paintContents: Layer.paintContents:
public void paintContents(MapGraphics g) {
if (g != null) {
paintLayers(g);
paintFeatures(g);
paintLayer(g);
}
}
Layer.paint: Layer.paint:
public void paint(MapGraphics g) {
if (isVisible()) {
Graphics2D g2d = g.getGraphics2D();
AffineTransform saveTransform = g2d.getTransform();
Composite saveComposite = g2d.getComposite();
Projection saveProjection = g.getProjection();
Style saveStyle = g.getStyle();
if (composite != null)
g2d.setComposite(composite);
if (transform != null)
g2d.transform(transform);
if (style != null)
g.setStyle(style);
if (projection != null)
g.setProjection(projection);
paintContents(g);
g.setStyle(saveStyle);
g.setProjection(saveProjection);
g2d.setComposite(saveComposite);
g2d.setTransform(saveTransform);
}
}
Layer.paintLayers: Layer.paintLayers:
public void paintLayers(MapGraphics g) {
for (Iterator<Layer> it = getLayersIterator(); it.hasNext();) {
Layer l = (Layer) it.next();
l.paint(g);
}
}
Globe.paint: Globe.paint:
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
// Turn on antialiasing - otherwise it looks horrible
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Put the origin at bottom left
g2.translate(0, getHeight());
g2.scale(1, -1);
// Put the globe in the middle
g2.translate(getWidth() / 2, getHeight() / 2);
Point2D.Float p = new Point2D.Float(1, 0);
transform.deltaTransform(p, p);
float rscale = 1.0f / (float) Math.sqrt(p.x * p.x + p.y * p.y);
g2.setStroke(new BasicStroke(rscale * 0.5f));
MapGraphics mg = MapGraphics.getGraphics(g2, new Rectangle(getSize()));
seaLayer.setVisible(showSea);
tissotLayer.setVisible(showTissot);
worldLayer.setVisible(showWorld);
graticuleLayer.setVisible(showGraticule);
map.paint(mg);
if (showNight) {
Color c = new Color(0, 0, 0, 0.5f);
GeneralPath gc = new GeneralPath();
ProjectionPainter.smallCircle(45, 5, 87, 180, gc, true);
gc.closePath();
ProjectionPainter pp = ProjectionPainter.getProjectionPainter(projection);
pp.drawPath(g2, gc, null, c);
}
}
I see in your stack trace a blanked out region defined by the line: 我在堆栈中看到由该行定义的空白区域:
SNIP - MY CALL TO PAINT THE LAYER
That code calls SunGraphics2D.draw(Shape)
. 该代码称为SunGraphics2D.draw(Shape)
。 I dont see that call in the code that you have edited in. However, it looks as though the Shape
that you are passing into SunGraphics2D.draw()
is null. 我没有在编辑过的代码中看到该调用。但是,看起来好像要传递给SunGraphics2D.draw()
的Shape
为空。
It means that while handling an event (looks like a repaint in this case) a NullPointerException was thrown. 这意味着在处理事件时(在这种情况下看起来像是重新绘制),抛出了NullPointerException。 That means you tried to call a method on an object, and it turned out to be null. 这意味着您尝试在对象上调用方法,结果却为空。
Something on line 70 in the paintContents() method of the com.jhlabs.map.layer.Layer class has a null reference. com.jhlabs.map.layer.Layer类的paintContents()方法中第70行上的内容具有空引用。
I don't know which IDE you are using, but in Eclipse you can tell the Debugger to break at specifiv types of exceptions, eg NPEs. 我不知道您使用的是哪个IDE,但是在Eclipse中,您可以告诉调试器打破特定类型的异常,例如NPE。
You could run your App in Debugmodus with this option turned on and try to reproduce the error so that you can check in your Debugger what's wrong. 您可以在启用此选项的情况下在Debugmodus中运行您的App,然后尝试重现该错误,以便可以在Debugger中检查出了什么问题。
Check if the source code of the sun lib is available. 检查sun lib的源代码是否可用。 If so: Instruct you debuger to hold execution when a NPE is thrown. 如果是这样:指示调试器在引发NPE时保持执行。 Then you can check the object that is null and guess (or backtrack) which object should be in that reference 然后,您可以检查为空的对象并猜测(或回溯)该引用中应包含哪个对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.