Invalid indirect reference on NewObject call

落花浮王杯 提交于 2019-12-05 05:10:45

OK, found it. It was a problem with the jstring parameters. It turns out you cannot pass empty strings (or even NULL for that matter) as a jstring. Instead I used (*env)->NewStringUTF(env, NULL) to create a NULL jstring.

Seems to work OK now.


Since this question generated somewhat a high activity, I'm posting the final solution below. Note that the nullString variable is being deallocated at the end of its scope (or when you're done using it):

        jstring nullString = (*env)->NewStringUTF(env, NULL);
...
        jobject permInfo = (*env)->NewObject(env, 
                                gFilePermInfoClass, 
                                filePermInfoClsConstructor, 
                                (jbyte)permsOwner,
                                (jbyte)permsGroup,
                                (jbyte)permsOthers,
                                (jlong)sb.st_uid,
                                (jlong)sb.st_gid,
                                (jlong)sb.st_atime,
                                (jlong)sb.st_mtime,
                                (jlong)sb.st_ctime,
                                nullString,
                                nullString,
                                (jboolean)1,
                                nullString);
...
       (*env)->DeleteLocalRef(env, nullString);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!