CallIntMethod导致-1 - ANDROID JNI [英] CallIntMethod result -1 - ANDROID JNI

查看:1380
本文介绍了CallIntMethod导致-1 - ANDROID JNI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从C中使用Android的共享preferences
为了方便使用,我有一个类和它的一些方法(getIniParamInt,getIniParamString等)的东西JAVA正常工作。

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.

问题是,如果我调用该方法从JNI它发回-1到C.
我的JAVA code的部分(简化测试,共享preF删除等):

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:

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;

总是与paramInt = -1返回;而不是999;

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

我已经挖了整个网络,我无法找到解决方案。
能否请你帮我,什么是错的CallIntMethod通话?
谢谢!

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!

推荐答案

嗯...我找到了解决办法!
问题是,在Java中code:
它必须声明所调用的方法为私有方法,而不是公众!

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.

这篇关于CallIntMethod导致-1 - ANDROID JNI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆