Ganesh kumar S R
Ganesh kumar S R

Reputation: 591

NoSuchMethodError for addall ArrayList in JNI

jclass class= env->FindClass("java/util/ArrayList"); 

listClass = (jclass)env->NewGlobalRef(class);   

listAddAllID = env->GetMethodID(listClass, "addAll", "(Ljava/lang/Object;)Z");

I got the following exception for the above code "java.lang.NoSuchMethodError: addAll".I used 'lang/object' for a parameter and 'z' for return type boolean.It seems to be right completely.What am I missing here?

public boolean addAll(Collection c)

Upvotes: 0

Views: 265

Answers (2)

user207421
user207421

Reputation: 310980

It seems to be right completely.

Incomprehensible. It is completely wrong. The API says the parameter is a Collection.

Don't guess at these things, and don't try to write JNI method sigmatures yourself. Use the output of javap -s. It is never wrong.

Upvotes: 0

Oo.oO
Oo.oO

Reputation: 13385

You can always use javap to get proper descriptor of method

> javap -s java.util.ArrayList | grep -A +1 addAll
  public boolean addAll(java.util.Collection<? extends E>);
    descriptor: (Ljava/util/Collection;)Z
--
  public boolean addAll(int, java.util.Collection<? extends E>);
    descriptor: (ILjava/util/Collection;)Z

So, you need to change it to one of these (depending on the call you want to make).

Have fun with JNI!

Upvotes: 1

Related Questions