一.本文是主要写GetFieldID,GetMethodID方法的使用
jclass clazz=(*env)->GetObjectClass(env,thiz);//其中的clazz就是Natvie class.
开始我在写这个程序的时候一直报GetFileId ..No such "value".
找了好久才发现 我在Native.java中定义的 和getValue()也是用static
然后定义的value不是static.
在fid=(*env)->GetFieldID(env,clazz,"value","Ljava/lang/String;"); 报错,是因为static方法中必须要用static的变量
所以我把getValue()方法的static方法去掉,下面是ok的代码。
我本来想全部用static来解决就是
fid=(*env)->GetStaticFieldID(env,clazz,"value","Ljava/lang/String;");
不知道什么原因,还是出现上面的错误。。后续来改。
今天试getMethodId();
mid=(*env)->GetMethodID(env,clazz,"showMessage","()V");//showMessage为Java中的方法,"()V"为该方法是return void的方法。
(*env)->CallVoidMethod(env,thiz,mid);
与GetMethodID相对应的是Call**Method().
对应static的属性一定要用static的属性。
fNumberId=(*env)->GetStaticFieldID(env,clazz,"number","I");
if(fNumberId==NULL)
return;
jint num=(*env)->GetStaticIntField(env,clazz,fNumberId);
//print(num);
(*env)->SetStaticIntField(env,clazz,fNumberId,2);
需要源码的请留言给出mail的地址。