I tried to work through the Feature Tutorial of geotools. Everything worked well until I got to the code where the Features should be stored in a shapefile:
if (featureSource instanceof SimpleFeatureStore) {
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
// List Features into Collection
SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, features);
featureStore.setTransaction(transaction);
try {
featureStore.addFeatures(collection);
transaction.commit();
}catch (Exception problem) {
problem.printStackTrace();
transaction.rollback();
}finally {
transaction.close();
}
System.exit(0);
}else {
System.out.println(typeName + "does not support read/write access.");
System.exit(0);
}
The runtime exception links to the row "featureStore.addFeatures(collection); This is the error message:
Exception in thread "main" java.lang.ClassFormatError: Illegal constant pool index 0 for method name in class file org/geotools/geometry/jts/JTS
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at org.geotools.feature.simple.SimpleFeatureImpl.getBounds(SimpleFeatureImpl.java:258)
at org.geotools.data.Diff.addToSpatialIndex(Diff.java:201)
at org.geotools.data.Diff.add(Diff.java:195)
at org.geotools.data.store.DiffContentFeatureWriter.write(DiffContentFeatureWriter.java:168)
at org.geotools.data.InProcessLockingManager$1.write(InProcessLockingManager.java:296)
at org.geotools.data.store.ContentFeatureStore.addFeature(ContentFeatureStore.java:302)
at org.geotools.data.store.ContentFeatureStore.addFeatures(ContentFeatureStore.java:254)
at de.topotools.topograph.Csv2Shape.main(Csv2Shape.java:121)
I updated the maven project and checked if the code is equal to the tutorial's code, but nothing helped. I could also not find any description of this error in relation to geotools searching the internet.
I'm using Java 14.0.2.
Thanks for your help.
It looks like your project is missing a jar or two. Also GeoTools doesn't really support any JVMs except 1.8 and 11, but always happy to hear it works in another versions.