java.lang.IncompatibleClassChangeError:在读取形状文件时实现类

时间:2019-02-22 07:26:37

标签: java jar shapefile geotools opengis

import org.opengis.feature.*;
import org.geotools.feature.*;
import org.geotools.data.*;
import java.io.*;
import java.util.*;
public class GeoOpen
{

public static void main(String[] args) {
File file = new File("states.shp");

try {
  Map<String, String> connect = new HashMap();
  connect.put("url", file.toURI().toString());

  DataStore dataStore = DataStoreFinder.getDataStore(connect);
  String[] typeNames = dataStore.getTypeNames();
  String typeName = typeNames[0];

  System.out.println("Reading content " + typeName);

  FeatureSource featureSource = dataStore.getFeatureSource(typeName);
  FeatureCollection collection = featureSource.getFeatures();
  FeatureIterator iterator = collection.features();


  try {
    while (iterator.hasNext()) {
      Feature feature = iterator.next();
      GeometryAttribute sourceGeometry = feature.getDefaultGeometryProperty();
    }
  } finally {
    iterator.close();
  }

} catch (Throwable e) {
    e.printStackTrace();}}
}

我一直试图在此代码中读取形状文件。但是当执行上面的文件时,得到java.lang.IncompatibleClassChangeError。我看到帖子收到类似的错误,这些错误通过使用最新的jar得以解决。即使使用最新的jar,我也会收到此错误。

java.lang.IncompatibleClassChangeError: Implementing class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.geotools.data.shapefile.ShpFiles.exists(ShpFiles.java:981)
    at org.geotools.data.shapefile.ShpFiles.init(ShpFiles.java:172)
    at org.geotools.data.shapefile.ShpFiles.<init>(ShpFiles.java:129)
    at org.geotools.data.shapefile.ShapefileDataStoreFactory.createDataStore(ShapefileDataStoreFactory.java:195)
    at org.geotools.data.shapefile.ShapefileDataStoreFactory.createDataStore(ShapefileDataStoreFactory.java:63)
    at org.geotools.data.DataAccessFinder.getDataStore(DataAccessFinder.java:129)
    at org.geotools.data.DataStoreFinder.getDataStore(DataStoreFinder.java:87)
    at GeoOpen.main(GeoOpen.java:16)

谢谢。

0 个答案:

没有答案