我可以让java代码调用jni,但是我在从jni调用java时遇到了麻烦,请看下面的代码和结果帮助我
在java中:
public class SocketClient {
private native void nativeInit();
public void Init()
{
nativeInit();
}
.........
public boolean IsConnected()
{
Log.i("Test", "Hien public boolean IsConnected()");
return _is_connected;
}
.......
我调用了 Init 方法
SocketClient socketClient = new SocketClient();
socketClient.Init();
在杰尼:
JNIEXPORT void Java_SocketClient_nativeInit (JNIEnv* env, jobject obj)
{
LOG_INFO("Hien2 Java_SocketClient_nativeInit at jni layer");
jclass cls = (*env)->GetObjectClass(env, obj);
jmethodID mid = (*env)->GetMethodID(env, cls, "IsConnected", "()Z");
int temp = (*env)->CallBooleanMethod(env, cls, mid);
LOG_INFO("Hien3 temp=%d", temp);
}
结果输出如下:
Hien2 Java_SocketClient_nativeInit at jni layer
Hien3 temp=168
不能调用 IsConnected() 中的代码!!!