According to GetStringUTFChars
, the last parameter is a pointer to jboolean
.
Change
return env->GetStringUTFChars(returnString, JNI_FALSE);
to
return env->GetStringUTFChars(returnString, NULL);
Or better yet, return a std::string
std::string DiagLayerContainer_getDESC(...) {
...
const char *js = env->GetStringUTFChars(returnString, NULL);
std::string cs(js);
env->ReleaseStringUTFChars(returnString, js);
return cs;
}
I've built a similar simple example and the code as is, seems fine so far.
Although, there are two possible error sources.
The first one is the method signature. Try "()Ljava/lang/String;"
instead of "(Ljava/lang/Object;)Ljava/lang/String;"
.
The second one is in the java source itself. If the java method returns a null string, CallObjectMethod()
will return a NULL jstring
and GetStringUTFChars()
fails.
Add a
if (returnString == NULL)
return NULL;
after CallObjectMethod()
.
So look into the java source and see, whether the method getDESCDiagLayer()
might return a null string.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…