jni中c语言调用类中类方法的问题?
java代码:
public class Hello {
private native int testCallSubClassMethod();

static{
System.loadLibrary("JavaTet");
}

public class arithmatic{
public int sub(int a, int b)
{
int c;
System.out.println("in java" );
System.out.println("a = " + a);
System.out.println("b = " + b);
c = a - b;
System.out.println("c = " + c);
return c;
}
}

private arithmatic tesAri;

public static void main(String[] args){
//System.out.print("succee");
Hello hl = new Hello();
int ret;
System.out.println("in java" );
ret = hl.testCallSubClassMethod();
System.out.println("ret = " + ret);

}
}我想在c语言中调用对象tesAri.sub方法
c语言的代码
JNIEXPORT jint JNICALL Java_test_Hello_testCallSubClassMethod(JNIEnv *env, jobject obj)
{
jmethodID mid;
jfieldID fid;
int ret;
jclass cls = (*env)->GetObjectClass(env, obj); jclass aricls;
jobject ariobj; printf("In C\n"); fid = (*env)->GetFieldID(env, cls, "tesAri", "Ltest/Hello$arithmatic;");
if (fid == NULL)
{
printf("find not obj id tesAri\n");
return -1;
} ariobj = (*env)->GetObjectField(env, obj, fid);
if (ariobj)
{
printf("not get the obj tesAri");
return -1;
}

//aricls = (*env)->GetObjectClass(env, ariobj);
aricls = (*env)->FindClass(env, "test/Hello$arithmatic");
if (aricls == NULL)
{
printf("not get the class arithmatic\n");
return -1;
} printf("get the class arithmatic\n"); mid = (*env)->GetMethodID(env, aricls, "sub", "(II)I");
if (mid == NULL)
{
printf("find not method sub\n");
return -1;
} printf("find method sub\n");
ret = (*env)->CallIntMethod(env, ariobj, mid, 10, 4);
printf("ret = %d\n", ret);
return ret;}c语言代码出错在ret = (*env)->CallIntMethod(env, ariobj, mid, 10, 4);报错信息:
Exception in thread "main" java.lang.NullPointerException
at test.Hello.testCallSubClassMethod(Native Method)
at test.Hello.main(Hello.java:87)这是为什么,为什么是空指针异常?要怎么解决?