Java – why can’t my JNI code successfully find the GetMessage method of jthrowable?

I'm trying to access the message in jthrowable and handle the exception generated when the class cannot be found However, I can't access the message ID of GetMessage () on the jthrowable object. I don't know why I've tried to change the signature of GetMessage to "() l Java / Lang / string" (there's no semicolon at the end, but it's necessary, isn't it?) No happiness I'm confused about it I even tried to replace GetMessage with toString, but it didn't work Obviously I did something very wrong here

This is the code I'm using:

jthrowable java_exception;
jclass java_class;
jmethodID method;

java_exception = (*jEnv)->ExceptionOccurred(jEnv);
assert (java_exception != NULL);
java_class = (*jEnv)->GetObjectClass (jEnv,java_exception);
assert (java_class != NULL);
method = (*jEnv)->getmethodID (jEnv,java_class,"getMessage","()Ljava/lang/String;");
if (method == NULL) {
printf ("SerIoUsly,how do I get here?!\n");
(*jEnv)->ExceptionDescribe (jEnv);
return;
}

The output of this code (and others) is as follows:

javap -p -s java. Lang. throwable gave me this:

Solution

Well, it seems that my problem is that getobjectclass does not run on jthrowable as you expected, or at least its results are useless for obtaining methods Replace the part of the code with this:

java_class = (*jEnv)->FindClass (jEnv,"java/lang/Throwable");
method = (*jEnv)->getmethodID (jEnv,"()Ljava/lang/String;");

That's strange, that However, I hope it will help others

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>