java - NoSuchMethodException while calling GeometryJSON().read() -
i using jts (from vividsolutions) , geotools. have following code:
public geometry jsontogeom(string json) throws ioexception { geometry obj = new geometryjson().read(json); return obj; }
however, returns following runtimeexception:
java.lang.runtimeexception: java.lang.nosuchmethodexception: org.geotools.geojson.feature.featurehandler.<init>(com.vividsolutions.jts.geom.geometryfactory) @ org.geotools.geojson.delegatinghandler.createdelegate(delegatinghandler.java:130) @ org.geotools.geojson.geom.geometryhandler.primitive(geometryhandler.java:68) @ org.json.simple.parser.jsonparser.parse(unknown source) @ org.json.simple.parser.jsonparser.parse(unknown source) @ org.geotools.geojson.geojsonutil.parse(geojsonutil.java:236) @ org.geotools.geojson.geom.geometryjson.parse(geometryjson.java:655) @ org.geotools.geojson.geom.geometryjson.read(geometryjson.java:196) @ am.abhi.experiments.geotoolstest.geojson.jsontogeom(geojson.java:13) @ am.abhi.experiments.geotoolstest.sometest.testsomething(sometest.java:22) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ junit.framework.testcase.runtest(testcase.java:176) @ junit.framework.testcase.runbare(testcase.java:141) @ junit.framework.testresult$1.protect(testresult.java:122) @ junit.framework.testresult.runprotected(testresult.java:142) @ junit.framework.testresult.run(testresult.java:125) @ junit.framework.testcase.run(testcase.java:129) @ junit.framework.testsuite.runtest(testsuite.java:255) @ junit.framework.testsuite.run(testsuite.java:250) @ org.junit.internal.runners.junit38classrunner.run(junit38classrunner.java:84) @ org.apache.maven.surefire.junit4.junit4provider.execute(junit4provider.java:252) @ org.apache.maven.surefire.junit4.junit4provider.executetestset(junit4provider.java:141) @ org.apache.maven.surefire.junit4.junit4provider.invoke(junit4provider.java:112) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.apache.maven.surefire.util.reflectionutils.invokemethodwitharray(reflectionutils.java:189) @ org.apache.maven.surefire.booter.providerfactory$providerproxy.invoke(providerfactory.java:165) @ org.apache.maven.surefire.booter.providerfactory.invokeprovider(providerfactory.java:85) @ org.apache.maven.surefire.booter.forkedbooter.runsuitesinprocess(forkedbooter.java:115) @ org.apache.maven.surefire.booter.forkedbooter.main(forkedbooter.java:75) caused by: java.lang.nosuchmethodexception: org.geotools.geojson.feature.featurehandler.<init>(com.vividsolutions.jts.geom.geometryfactory) @ java.lang.class.getconstructor0(class.java:2849) @ java.lang.class.getconstructor(class.java:1718) @ org.geotools.geojson.delegatinghandler.createdelegate(delegatinghandler.java:123) ... 33 more
on stepping through code, found method in org.geotools.geojson.delegatinghandler causes error:
protected icontenthandler createdelegate(class clazz, object[] args) { try { if (args != null && args.length > 0) { class[] types = new class[args.length]; (int = 0; < args.length; i++) { types[i] = args[i].getclass(); } return (icontenthandler) clazz.getconstructor(types).newinstance(args); } else { return (icontenthandler) clazz.newinstance(); } } catch (exception e) { throw new runtimeexception(e); } }
on line return (icontenthandler) clazz.getconstructor(types).newinstance(args)
.
it fails when calls featurehandler , tries pass geometryfactory argument. on jts 1.8 , geotools 13-snapshot.
any or workaround appreciated.
you have wrong version of jts - suspect means didn't use maven. need version 1.13 work geotools 13-snapshot.
$ mvn dependency:tree [info] scanning projects... [info] [info] using builder org.apache.maven.lifecycle.internal.builder.singlethreaded.singlethreadedbuilder thread count of 1 [info] [info] ------------------------------------------------------------------------ [info] building geojson support 13-snapshot [info] ------------------------------------------------------------------------ [info] [info] --- maven-dependency-plugin:2.8:tree (default-cli) @ gt-geojson --- [info] org.geotools:gt-geojson:jar:13-snapshot [info] +- org.geotools:gt-main:jar:13-snapshot:compile [info] | +- org.geotools:gt-api:jar:13-snapshot:compile [info] | +- com.vividsolutions:jts:jar:1.13:compile [info] | \- org.jdom:jdom:jar:1.1.3:compile [info] +- com.googlecode.json-simple:json-simple:jar:1.1:compile [info] +- org.geotools:gt-epsg-hsql:jar:13-snapshot:test [info] | +- org.geotools:gt-referencing:jar:13-snapshot:compile [info] | | +- java3d:vecmath:jar:1.3.2:compile [info] | | +- commons-pool:commons-pool:jar:1.5.4:compile [info] | | +- org.geotools:gt-metadata:jar:13-snapshot:compile [info] | | | \- org.geotools:gt-opengis:jar:13-snapshot:compile [info] | | | \- net.java.dev.jsr-275:jsr-275:jar:1.0-beta-2:compile [info] | | \- jgridshift:jgridshift:jar:1.0:compile [info] | \- org.hsqldb:hsqldb:jar:2.2.8:test [info] +- javax.media:jai_core:jar:1.1.3:compile [info] \- junit:junit:jar:4.11:test [info] \- org.hamcrest:hamcrest-core:jar:1.3:test
Comments
Post a Comment