使用JNI检索jint值时的随机值 [英] Random values when retrieving jint value using JNI
问题描述
我正在使用JNI将类型为'Properties'的java对象传递给c ++.
I am passing a java object of type 'Properties' to c++ using JNI.
我使用以下语句检索插入到Properties对象中的int值.
I retrieve an int value that is inserted into the Properties object using the following statements.
int intVal = 1;
Properties propObj = new Properties();
propObj.put("KEY_FOR_INT", intVal);
当我尝试使用带有以下语句的JNI在c ++中检索值时,我会得到随机值.
When i try to retrieve the value in c++ using JNI with the following statement, i get random values.
jint intValueFromJava = env->CallIntMethod(propObj, propGetID, env->NewStringUTF("KEY_FOR_INT"));
如果我尝试检索字符串值或ArrayList,则可以正确获取它.
If i try to retrieve a string value or ArrayList, i am able to get it correctly.
推荐答案
尝试查看调用后是否发生了异常
try to see if an exception occurred after the call
jint intValueFromJava = env->CallIntMethod(propObj, propGetID, env->NewStringUTF("KEY_FOR_INT"));
jthrowable exc = env->ExceptionOccurred();
您正在调用的方法有可能返回一个Object而不是一个int(如果是)
It is possible that the method you are calling returns an Object rather then an int, if it is
public synchronized V get(Object key);
使用jni暂时无法使用,但拆箱可能无法正常工作.
Didn't work for a while with jni but it possible that unboxing does not work.
这篇关于使用JNI检索jint值时的随机值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!