問題を追跡するために何かをしようとしていますが、paintContents までできることはあまりなく、デバッガーでそこにあるものはすべて問題ないように見えますが、何も見逃していないことを確認するために再確認します。少なくとも、これらを静かに処理する方法を知りたいです (それらをキャッチして、意味のあるエラーメッセージを出力できるようにするなど)。
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)
次のソース コードは、Java Map Projection Libraryからのものです。
Layer.paintContents:
public void paintContents(MapGraphics g) {
if (g != null) {
paintLayers(g);
paintFeatures(g);
paintLayer(g);
}
}
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:
public void paintLayers(MapGraphics g) {
for (Iterator<Layer> it = getLayersIterator(); it.hasNext();) {
Layer l = (Layer) it.next();
l.paint(g);
}
}
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);
}
}