日期:2014-05-20 浏览次数:20869 次
package test;
public class A
{
public int num;
}
package test;
public class B
{
public static native A getA();
static
{
System.loadLibrary("A");
}
public static void main(String[] args)
{
System.out.println(getA().num);
}
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class test_B */
#ifndef _Included_test_B
#define _Included_test_B
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: test_B
* Method: getA
* Signature: ()Ltest/A;
*/
JNIEXPORT jobject JNICALL Java_test_B_getA
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
#include "test_B.h"
/*
* Class: test_B
* Method: getA
* Signature: ()Ltest/A;
*/
JNIEXPORT jobject JNICALL Java_test_B_getA
(JNIEnv * env, jclass cl)
{
jclass class_A = (*env)->FindClass(env, "test.A"); //我已经调试过了,这句执行后class_A的结果为null
jfieldID fid_A_num = (*env)->GetFieldID(env, class_A, "num", "I");
jmethodID mid_A = (*env)->GetMethodID(env, class_A, "<init>", "()V");
jobject obj_A_a = (*env)->NewObject(env, class_A, mid_A);
(*env)->SetIntField(env, obj_A_a, fid_A_num, 100);
return obj_A_a;
}