CallIntMethod result -1 - ANDROID JNI

南笙酒味 提交于 2019-12-24 15:38:19

问题


I would like to use the ANDROID SharedPreferences from C. For easier usage, I've a class and some methods for it (getIniParamInt, getIniParamString etc.) The things works fine in JAVA.

The problem is, if I call the method from jni it sends back -1 to C. Parts of my JAVA code (simplified for test, SharedPref. removed etc.):

public class IniManipulate {
   public int getIniParamInt(String mezoNev)
                  {return 999;}  // settings.getInt("abc", -9999);

C code:

const char* paramOut 
paramOut = "abc";
jmethodID mid = (*env)->GetMethodID(env,cls1,"getIniParamInt","(Ljava/lang/String;)I");
     if (mid == NULL) {cDebug1 = 888;return; }
jstring* parameter = (*env)->NewStringUTF(env, paramOut);
     if (parameter == NULL) {return;}
jint paramInt = (jint) (*env)->CallIntMethod(env,thiz, mid, parameter);
cDebug1 = (int)paramInt;

Always returns with paramInt=-1; instead of 999;

I've already digged up the whole web and I couldn't find the solution. Could you please help me, what's wrong with the CallIntMethod calling? Thanks!


回答1:


Hmm... I found the SOLUTION! The problem is, in Java code: It must declare the called method as private method instead of public!!!

private int getIniParamInt(String mezoNev)
              {return 999;} 

I'm a beginner, so I don't know the real explanation... I just tried it. I hope it's helpful for people who wants use method like this.



来源:https://stackoverflow.com/questions/9253389/callintmethod-result-1-android-jni

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!