How to get a String from JNI?
I want to get a returned String from JNI, but I don't know how to do it, my code are follows:
//MyNative.java
public class MyNative{
public String test1(String s){
return test11(s);
}
private native String test11(String s);
static{
System.loadLibrary( "MyNative" );
}
public static void main( String[] args ){
MyNative obj = new MyNative();
String c=obj.test1("abc");
System.out.println("--"+c);
}
}
//MyNative.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class MyNative */
#ifndef _Included_MyNative
#define _Included_MyNative
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: MyNative
* Method: test11
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_MyNative_test11
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
}
#endif
#endif
//MyNative.c
#include <stdio.h>
#include "MyNative.h"
JNIEXPORT jstring JNICALL Java_MyNative_test11
(JNIEnv *env, jobject obj, jstring s){
//How to realize return String to Java???,such as return a string "hello world",how to realize this function,please give example code.
}
Thanks in advance!
|