So I have stumbled on this error, whenever I try to remove an element from a JsonArray object, i get the NoSuchMethodException. But after looking at it for a solid day, i cannot find the reason for it. The method exists in the compiled .class file in the .jar file that is included in my project. And I'm at loss now. Surely the problem is between the chair and keyboard, but I just don't see it
EDIT: after compiling the project i don't get this error, so this has to do something with how eclipse is managing dependencies, because one project does use gson-2.2.4
I'm using gson 2.3 jar which I included via maven and even downloaded the jar file itself.
Example piece of code where the error is 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 is thrown here
} else if (buckets.isJsonObject()) {
Set<Entry<String,JsonElement>> entrySet = buckets.getAsJsonObject().entrySet();
for (Entry<String, JsonElement> entry : entrySet) {
next = entry.getValue();
buckets.getAsJsonObject().remove(entry.getKey());
break;
}
}
}
when i compile my project using maven i can see that maven is using gson 2.3
[INFO] Expanding: /Users/####/.m2/repository/com/google/code/gson/gson/2.3/gson-2.3.jar into /Users/####/Documents/workspace/proj_name/target/assembly/work/gson-2.3.jar
output of javap ~/Downloads/gson-2.3/com/google/gson/JsonArray.class
from the jar file that is in classpath of my java project
Compiled from "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); <---- It 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(); }
Exception in thread "main" java.lang.NoSuchMethodError: com.google.gson.JsonArray.remove(I)Lcom/google/gson/JsonElement;
this is the whole stacktrace, then there are just the java files in my project and no ther indication – Gabriel