0

Eclipse http://docs.geotools.org/latest/userguide/tutorial/quickstart/eclipse.html を使用して Geotools クイックスタート チュートリアルを見ていました。

クイックスタート クラスを実行すると。このエラーが発生しました

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 に何か問題がありますか?

ありがとう

4

2 に答える 2

1

Geotools クイックスタート チュートリアルも試してみましたが、同じ問題がありました。

最後に追加します:

import org.geotools.data.shapefile.*;

変更する

FileDataStore store = FileDataStoreFinder.getDataStore(file);

ShapefileDataStore store = new ShapefileDataStore(file.toURI().toURL());

例外の問題は解決しませんが、代わりになる可能性があります。

于 2012-02-09T08:10:01.423 に答える
1

おそらくsun.awt.shell.Win32ShellFolder2.getFileSystemPath、NPE をトリガーするメソッドのバグです。

問題を解決するには、JDK 1.6.0u21 以降を使用することをお勧めします。

キーワードでGoogleでチェック"NullPointerException sun.awt.shell.Win32ShellFolder2"

于 2011-10-13T08:17:19.690 に答える