Java Geotools Quickstart教程JFileDataStoreChooser.showOpenFile导致错误
我正在看使用Eclipse的Geotools快速入门教程 我遵循了所有的步骤,一切顺利,直到我运行了Quickstart类 当我运行Quickstart类时。我犯了这个错误Java Geotools Quickstart教程JFileDataStoreChooser.showOpenFile导致错误,java,eclipse,swing,geotools,Java,Eclipse,Swing,Geotools,我正在看使用Eclipse的Geotools快速入门教程 我遵循了所有的步骤,一切顺利,直到我运行了Quickstart类 当我运行Quickstart类时。我犯了这个错误 Exception in thread "main" java.lang.NullPointerException at sun.awt.shell.Win32ShellFolder2.getFileSystemPath(Win32ShellFolder2.java:571) at sun.awt.shell
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;
导入java.io.File;
导入org.geotools.data.FileDataStore;
导入org.geotools.data.FileDataStoreFinder;
导入org.geotools.data.simple.SimpleFeatureSource;
导入org.geotools.map.FeatureLayer;
导入org.geotools.map.Layer;
导入org.geotools.map.MapContent;
导入org.geotools.style.SLD;
导入org.geotools.Style.Style;
导入org.geotools.swing.JMapFrame;
导入org.geotools.swing.data.jfiledatastoreselector;
/**
*提示用户输入形状文件,并在地图框中显示屏幕上的内容。
*
*这是文档和教程中使用的GeoTools Quickstart应用程序*
*/
公共类快速入门{
/**
*GeoTools Quickstart演示应用程序。提示用户输入形状文件并显示其
*地图框中屏幕上的内容
*/
公共静态void main(字符串[]args)引发异常{
//显示ShapeFile的数据存储文件选择器对话框
/*********这是电话线*********/
File File=jfiledatastoreselector.showOpenFile(“shp”,null);
/***********************************/
//if(file==null){
//返回;
// }
//
//FileDataStore store=FileDataStoreFinder.getDataStore(文件);
//SimpleFeatureSource featureSource=store.getFeatureSource();
//
////创建地图内容并将我们的形状文件添加到其中
//MapContent map=新的MapContent();
//map.setTitle(“快速启动”);
//
//Style Style=SLD.createSimpleStyle(featureSource.getSchema());
//图层=新的FeatureLayer(featureSource,style);
//map.addLayer(层);
//
////现在显示地图
//showMap(map);
}
}
另外,在pom.xml中,我尝试了8.0-M2和8-SNAPSHOT版本。但是没有运气
有人有什么想法吗?
模块geotools.swing是否有问题
谢谢可能是sun.awt.shell.Win32ShellFolder2.GetFileSystemPassive方法的一个bug触发了NPE 有人建议使用JDK1.6.0u21或更高版本来解决这个问题
使用关键字“NullPointerException sun.awt.shell.Win32ShellFolder2”查看Google我也在尝试Geotools快速入门教程,我遇到了同样的问题 我最后补充:
导入org.geotools.data.shapefile.*代码>
改变
FileDataStore store=FileDataStoreFinder.getDataStore(文件)代码>
借
ShapefileDataStore=新的ShapefileDataStore(file.toURI().toul())代码>
它不能解决异常问题,但可以作为一种选择。谢谢您的回答。我试着用谷歌搜索关键词。在,它说它在6u21中修复,在,它说恢复到6u18版本。我尝试了这两种方法,仍然得到了NullPointerException,但堆栈跟踪不同。我的原始版本是JDK 7
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);
}
}