Java 如何在swing应用程序中包含shapefile

Java 如何在swing应用程序中包含shapefile,java,swing,geotools,Java,Swing,Geotools,我是新的地理信息系统为基础的项目。我正在使用netbeans IDE包含我的shapefile,我确信我已经导入了必要的JAR来包含shapefile。但它不起作用。当我运行应用程序时,simplefeaturesource方法中出现空指针异常。在此我包括我的计划 public class Quickstart { /** * GeoTools Quickstart demo application. Prompts the user for a shapefile and

我是新的地理信息系统为基础的项目。我正在使用netbeans IDE包含我的shapefile,我确信我已经导入了必要的JAR来包含shapefile。但它不起作用。当我运行应用程序时,simplefeaturesource方法中出现空指针异常。在此我包括我的计划

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
        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);
    }
}
根据报告:

依次检查每个可用的数据源实现,并返回声称支持给定文件的第一个实现

参数:

  • 文件-文件
返回:
声称处理所需资源的第一个数据源,如果找不到,则返回null

现在,在它失败的实例中,它将返回null,在这种情况下,在上面的代码中,store将等于null。由于不会使用if语句检查存储区,以说明它是否为null,所以只会继续声明和初始化,您只希望得到最好的结果,因此下一行将生成null指针异常


这就是我对你的代码的看法。尝试并调试它,看看store是否等于null,或者在前面的行中使用if语句。

对不起,连接到哪里?stacktrace在哪里?您是否使用maven来确保所有jar都正确?
public static FileDataStore getDataStore(File file)
                                  throws IOException