我有一个使用 JUNG2 可视化大图的小程序。不久前,我设法添加了一个导出功能,允许用户将图形导出为基于矢量的图像,这次使用的是 FreeHEP 库。一切都很顺利(我什至在出版物中使用了 PDF 导出)。
现在,当我尝试导出图表时,小程序似乎崩溃了。深入研究 Java 控制台,我发现这是由于库深处存在 NPE。以下是堆栈跟踪的相关部分:
Exception in thread "AWT-EventQueue-2" java.lang.ExceptionInInitializerError
at org.freehep.graphicsio.gif.GIFImageWriteParam.<init>(GIFImageWriteParam.java:28)
at org.freehep.graphicsio.gif.GIFImageWriter.getDefaultWriteParam(GIFImageWriter.java:73)
at org.freehep.graphicsio.exportchooser.ImageExportFileType.<init>(ImageExportFileType.java:71)
at org.freehep.graphicsio.exportchooser.ImageIOExportFileType.onRegistration(ImageIOExportFileType.java:50)
at javax.imageio.spi.SubRegistry.registerServiceProvider(ServiceRegistry.java:715)
at javax.imageio.spi.ServiceRegistry.registerServiceProvider(ServiceRegistry.java:302)
at org.freehep.util.export.ExportFileTypeRegistry.addApplicationClasspathExportFileTypes(ExportFileTypeRegistry.java:122)
at org.freehep.util.export.ExportFileTypeRegistry.getDefaultInstance(ExportFileTypeRegistry.java:50)
at org.freehep.util.export.ExportFileType.getExportFileTypes(ExportFileType.java:181)
at org.freehep.util.export.ExportFileType.getExportFileTypes(ExportFileType.java:173)
at org.freehep.util.export.ExportDialog.addAllExportFileTypes(ExportDialog.java:64)
at org.freehep.util.export.ExportDialog.<init>(ExportDialog.java:130)
at org.freehep.util.export.ExportDialog.<init>(ExportDialog.java:90)
at org.freehep.util.export.ExportDialog.<init>(ExportDialog.java:82)
at myproject.visualization.ExtendedModelGraphMouse$ExportActionListener.actionPerformed(ExtendedModelGraphMouse.java:167)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
...
Caused by: java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.freehep.graphics2d.PixelGraphics2D.<clinit>(PixelGraphics2D.java:101)
... 53 more
我一直在研究 FreeHEP 库(托管在 Grep Code)的源代码,堆栈跟踪中的最后一行(最顶层)指向以开头的行UserProperties
public GIFImageWriteParam(Locale locale) {
super(locale);
canWriteProgressive = true;
progressiveMode = MODE_DEFAULT;
UserProperties def = new UserProperties(GIFGraphics2D
.getDefaultProperties());
quantizeColors = def.isProperty(GIFGraphics2D.QUANTIZE_COLORS);
quantizeMode = def.getProperty(GIFGraphics2D.QUANTIZE_MODE);
}
据我所知,这应该意味着GIFGraphics2D
结果是null
- 为什么,我不明白。我已经仔细检查了我的构建文件以确保必要的库已经到位,并且我的构建文件和我使用的代码ExportDialog
(请参阅问题正文中的第一个链接)在一年多的时间里都没有改变。那么这里的问题可能是什么?