CallIntMethod 结果 -1 - ANDROID JNI
我想使用 C 中的 ANDROID SharedPreferences。 为了更容易使用,我有一个类和一些方法(getIniParamInt、getIniParamString 等)。这些东西在 JAVA 中运行良好。
问题是,如果我从 jni 调用该方法,它会将 -1 发送回 C。 我的 JAVA 代码部分(简化测试、SharedPref.removed 等):
public class IniManipulate {
public int getIniParamInt(String mezoNev)
{return 999;} // settings.getInt("abc", -9999);
C 代码:
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;
始终返回 paramInt=-1;而不是 999;
我已经翻遍了整个网络,但找不到解决方案。 您能帮我看看 CallIntMethod 调用有什么问题吗? 谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯...我找到了解决方案!
问题是,在 Java 代码中:
它必须将被调用的方法声明为私有方法而不是公共方法!
我是初学者,所以我不知道真正的解释......我只是尝试了一下。
我希望它对想要使用这种方法的人有所帮助。
Hmm... I found the SOLUTION!
The problem is, in Java code:
It must declare the called method as private method instead of public!!!
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.