c通过JNI调用java,不能访问构造方法
java代码:
public class Simple2
{
int num;
static int snum = 0; //没运行一次getDoudble,snum+1
public Simple2(int num){
this.num = num;
}
public static int getNum(){
return snum;
}
public int getDoudble(){
snum = snum + 1;
return 2*num;
}
};
c语言部分代码:
jclass cls;
jmethodID mid;
jobject jobj;
cls = env->FindClass("Simple2");
if(cls != 0)
{
mid = env->GetStaticMethodID(cls,"getNum","()I");
if(mid != 0)
{
result = env->CallStaticIntMethod(cls,mid);
printf("第一次getNum为:%d\n",result);
}
mid = env->GetMethodID(cls,"<INIT>","(I)U"); if(mid != 0)
{
jobj = env->NewObject(cls,mid,18); //将18传入
printf("init ok!\n");
}
mid = env->GetMethodID(cls,"getDoudble","()I");
if(mid !=0 )
{
result = env->CallIntMethod(jobj,mid); //后面可以继续加参数
printf("调用getDoudble为:%d\n",result);
}
mid = env->GetStaticMethodID(cls,"getNum","()I");
if(mid != 0)
{
result = env->CallStaticIntMethod(cls,mid);
printf("第二次getNum为:%d\n",result);
}
}
运行到红色部分,直接失败,导致后面运行出错,不知道有没有高手知道怎么解决。
------解决方案--------------------mid = env->GetMethodID(cls,"<INIT>","(I)U")
没看到这个方法
------解决方案--------------------坐等高手
------解决方案--------------------native啊
------解决方案--------------------
mid = env->GetMethodID(cls,"<init>","(I)V")
------解决方案--------------------不懂啊,帮顶
祝楼主好运