Geotools 快速入门教程 JFileDataStoreChooser.showOpenFile 导致错误
我正在查看使用 Eclipse 的 Geotools 快速入门教程 http://docs.geotools.org/latest/userguide/tutorial/quickstart /eclipse.html 我遵循了所有步骤,一切都很顺利,直到我运行快速入门课程
当我运行快速入门课程时。我收到此错误
Exception in thread "main" java.lang.NullPointerException
at sun.awt.shell.Win32ShellFolder2.getFileSystemPath(Win32ShellFolder2.java:571)
at sun.awt.shell.Win32ShellFolder2.access$400(Win32ShellFolder2.java:72)
at sun.awt.shell.Win32ShellFolder2$2.call(Win32ShellFolder2.java:298)
at sun.awt.shell.Win32ShellFolder2$2.call(Win32ShellFolder2.java:296)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Win32ShellFolderManager2.java:502)
at java.lang.Thread.run(Thread.java:722)
并且我发现此方法导致了问题 JFileDataStoreChooser.showOpenFile
我注释掉了除使用上述方法的行之外的所有其他行,但仍然遇到相同的错误。 (如果我也评论该行,则没有错误)
package org.geotools.tutorial;
import java.io.File;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;
/**
* Prompts the user for a shapefile and displays the contents on the screen in a map frame.
* <p>
* This is the GeoTools Quickstart application used in documentationa and tutorials. *
*/
public class Quickstart {
/**
* GeoTools Quickstart demo application. Prompts the user for a shapefile and displays its
* contents on the screen in a map frame
*/
public static void main(String[] args) throws Exception {
// display a data store file chooser dialog for shapefiles
/*********This is the line *********/
File file = JFileDataStoreChooser.showOpenFile("shp", null);
/***********************************/
// if (file == null) {
// return;
// }
//
// FileDataStore store = FileDataStoreFinder.getDataStore(file);
// SimpleFeatureSource featureSource = store.getFeatureSource();
//
// // Create a map content and add our shapefile to it
// MapContent map = new MapContent();
// map.setTitle("Quickstart");
//
// Style style = SLD.createSimpleStyle(featureSource.getSchema());
// Layer layer = new FeatureLayer(featureSource, style);
// map.addLayer(layer);
//
// // Now display the map
// JMapFrame.showMap(map);
}
}
另外,在 pom.xml 中,我尝试了版本 8.0-M2 和 8-SNAPSHOT。但运气不好...
有人有什么想法吗? 模块 geotools.swing 有问题吗?
谢谢
I was looking at the Geotools Quickstart tutorial using Eclipse
http://docs.geotools.org/latest/userguide/tutorial/quickstart/eclipse.html
I followed all the steps and it all went well until I ran the Quickstart class
When I run the Quickstart class. I got this error
Exception in thread "main" java.lang.NullPointerException
at sun.awt.shell.Win32ShellFolder2.getFileSystemPath(Win32ShellFolder2.java:571)
at sun.awt.shell.Win32ShellFolder2.access$400(Win32ShellFolder2.java:72)
at sun.awt.shell.Win32ShellFolder2$2.call(Win32ShellFolder2.java:298)
at sun.awt.shell.Win32ShellFolder2$2.call(Win32ShellFolder2.java:296)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Win32ShellFolderManager2.java:502)
at java.lang.Thread.run(Thread.java:722)
And I found out that this method is causing the problem JFileDataStoreChooser.showOpenFile
I commented out all the other lines except for the one using the method above, and still got the same error. (there is no error if I commented that line as well)
package org.geotools.tutorial;
import java.io.File;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;
/**
* Prompts the user for a shapefile and displays the contents on the screen in a map frame.
* <p>
* This is the GeoTools Quickstart application used in documentationa and tutorials. *
*/
public class Quickstart {
/**
* GeoTools Quickstart demo application. Prompts the user for a shapefile and displays its
* contents on the screen in a map frame
*/
public static void main(String[] args) throws Exception {
// display a data store file chooser dialog for shapefiles
/*********This is the line *********/
File file = JFileDataStoreChooser.showOpenFile("shp", null);
/***********************************/
// if (file == null) {
// return;
// }
//
// FileDataStore store = FileDataStoreFinder.getDataStore(file);
// SimpleFeatureSource featureSource = store.getFeatureSource();
//
// // Create a map content and add our shapefile to it
// MapContent map = new MapContent();
// map.setTitle("Quickstart");
//
// Style style = SLD.createSimpleStyle(featureSource.getSchema());
// Layer layer = new FeatureLayer(featureSource, style);
// map.addLayer(layer);
//
// // Now display the map
// JMapFrame.showMap(map);
}
}
Also, in pom.xml, I tried versions 8.0-M2 and 8-SNAPSHOT. but no luck...
Anyone has any ideas?
Is there something wrong with module geotools.swing?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是
sun.awt.shell.Win32ShellFolder2.getFileSystemPath
方法的错误触发了 NPE。建议使用JDK 1.6.0u21以上版本来解决。
使用关键字
"NullPointerException sun.awt.shell.Win32ShellFolder2"
在 Google 上检查Probably it is a bug with
sun.awt.shell.Win32ShellFolder2.getFileSystemPath
method that triggers the NPE.One suggests to use JDK 1.6.0u21 or above to solve it.
Check on Google with keywords
"NullPointerException sun.awt.shell.Win32ShellFolder2"
我也一直在尝试 Geotools 快速入门教程,但遇到了同样的问题。
我最后添加:
import org.geotools.data.shapefile.*;
并更改
FileDataStore store = FileDataStoreFinder.getDataStore(file);
by
ShapefileDataStore store = new ShapefileDataStore (file.toURI().toURL());
它并没有解决异常的问题,但它可以作为替代方案。
I have been also trying the Geotools Quickstart tutorial and I had the same problem.
I finally add:
import org.geotools.data.shapefile.*;
and change
FileDataStore store = FileDataStoreFinder.getDataStore(file);
by
ShapefileDataStore store = new ShapefileDataStore(file.toURI().toURL());
It doesn't solve the question of the exception but it can be an alternative.