Sunday, 15 June 2014

java - NoSuchMethodException in Gson JsonArray -



java - NoSuchMethodException in Gson JsonArray -

so have stumbled on error, whenever seek remove element jsonarray object, nosuchmethodexception. after looking @ solid day, cannot find reason it. method exists in compiled .class file in .jar file included in project. , i'm @ loss now. certainly problem between chair , keyboard, don't see it

edit: after compiling project don't error, has how eclipse managing dependencies, because 1 project utilize gson-2.2.4

i'm using gson 2.3 jar included via maven , downloaded jar file itself.

example piece of code error thrown:

else if (current.isjsonobject() && hasbucket(current)) { jsonelement buckets = current.getasjsonobject().get(buckets); jsonelement next = null; if (buckets.isjsonarray() && buckets.getasjsonarray().size()>0) { jsonarray arr = buckets.getasjsonarray(); arr.remove(0); //<--- exception thrown here } else if (buckets.isjsonobject()) { set<entry<string,jsonelement>> entryset = buckets.getasjsonobject().entryset(); (entry<string, jsonelement> entry : entryset) { next = entry.getvalue(); buckets.getasjsonobject().remove(entry.getkey()); break; } } }

when compile project using maven can see maven using gson 2.3

[info] expanding: /users/####/.m2/repository/com/google/code/gson/gson/2.3/gson-2.3.jar /users/####/documents/workspace/proj_name/target/assembly/work/gson-2.3.jar

output of javap ~/downloads/gson-2.3/com/google/gson/jsonarray.class jar file in classpath of java project

compiled "jsonarray.java" public final class com.google.gson.jsonarray extends com.google.gson.jsonelement implements java.lang.iterable { public com.google.gson.jsonarray(); com.google.gson.jsonarray deepcopy(); public void add(com.google.gson.jsonelement); public void addall(com.google.gson.jsonarray); public com.google.gson.jsonelement set(int, com.google.gson.jsonelement); public boolean remove(com.google.gson.jsonelement); public com.google.gson.jsonelement remove(int); <---- exists! public boolean contains(com.google.gson.jsonelement); public int size(); public java.util.iterator iterator(); public com.google.gson.jsonelement get(int); public java.lang.number getasnumber(); public java.lang.string getasstring(); public double getasdouble(); public java.math.bigdecimal getasbigdecimal(); public java.math.biginteger getasbiginteger(); public float getasfloat(); public long getaslong(); public int getasint(); public byte getasbyte(); public char getascharacter(); public short getasshort(); public boolean getasboolean(); public boolean equals(java.lang.object); public int hashcode(); com.google.gson.jsonelement deepcopy(); }

there wrong build setup.

jsonarray.remove(int) introduced in version 2.3 of gson. happening compiling against right version (2.3), version getting packaged in apk not right version.

java gson

No comments:

Post a Comment