Krystian
Krystian

Reputation: 3423

JNI: NoSuchFieldError error where clearly the field exists with correct signature

I have a java class:

public class ClassOne implements Serializable {
    private String bField;
    private ArrayList<SomeClass> aField = new ArrayList<SomeClass>();
}

And I try to use it in C this way:

jlong
Java_ClassJNI_getArrayContent( JNIEnv* env, jobject this,
                                                jobject argument, jlong handle, jint isFirst) {

    jfieldID fid_bField, fid_aField;
    jclass cls = (*env)->GetObjectClass(env, argument); 
    fid_bField = (*env)->GetFieldID(env, cls, "bField", "Ljava/lang/String;");   
    fid_aField = (*env)->GetFieldID(env, cls, "aField", "Ljava.util.ArrayList;");

...

I get this error:

   java.lang.NoSuchFieldError: no field with name='aField' signature='Ljava.util.ArrayList;' in class LClassOne;

I have already cleaned and rebuilt the app and I keep getting this. It's a code that has always work and somehow stopped, with no changes to the class at all. I did git reset to make sure I didn't screw up anywhere, but nada. It still throws the same error.

I did debug the app to make sure that the objects passed are correct, and they are. The class is correct, the bField is picked up correctly, but the aField throws an error.

I have tried changing ArrayList<SomeClass> to ArrayList but it has changed nothing.

I'm quite lost with that, do you have any idea why this would happen?

Upvotes: 1

Views: 639

Answers (1)

user2543253
user2543253

Reputation: 2173

The descriptor should be "Ljava/util/ArrayList;". Slashes instead of dots.

Upvotes: 3

Related Questions