How do I access return value of a Java method returning java.lang.String from C++ in JNI? -


I'm trying to return a string with the Java method called C ++. I am not able to figure out how to call the JNI function to use the method and return a jestring value.

My code is as follows:

C + Part

  Main () {jclass cls; JmethodID Middle; Jstring rv; / ** ... Abandoned code ... * / cls = env- & gt; FindClass ("Classifier Vapor"); Mid = avi-> GetMethodID (CLS, "Getstring", "() Lijava / Lang / String"); RV = ANV-> callstatic & lt; TYPE & gt; Method (CLS, Middle, 0); Const char * Stratan = &-> GetStringutforhars (NV, RV, 0); Envi-> gt; Release Stratan (R.V., Stretton); } Public Code classifier {public string getString () {return "test";}}  

Java code

  code>  

method sign (from "javap -s class")

  public java.lang.String getString (); Signature: () Ljava / lang / String;  

you should be

  cls = env- & Gt; FindClass ("ClassifierWrapper");  

Then you need to start the constructor to get a new object:

  jmethodID classifier converstor = env-> GetMethodID (CLS, "& lt; init>", "() V"); If (classifier file constructor == tap) {return tap; / * Exception is thrown / job classifier, Obj = AV-> New object (CLS, Classifier constructor);  

You are getting a static method (even if the name of the method is false). Since GetString () is not static, you need to get the example method.

);

Now call the method:

  rv = env-> Call object method (classifier obz, gatestring meth, 0); Const char * Stratan = &-> GetStringutforhars (NV, RV, 0);  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -