由于可能的原因,这个JNI代码没有返回正确的值?

时间:2013-05-28 14:24:35

标签: android java-native-interface

由于可能的原因,此JNI代码未返回值nbField?

JNIEXPORT jint JNICALL Java_com_morpho_morphosmart_sdk_MorphoDatabaseNative_getNbField
 (JNIEnv *i_env, jobject thisObj, jlong morphoDatabasePointerCPP, jobject nbField){

I   l_i_Ret;
UL  l_ul_NbField;

l_i_Ret = dataBase->GetNbField(l_ul_NbField);
    // l_ul_NbField is equal 2 after here

if(l_i_Ret == 0) // l_i_Ret is not null
{
    jclass longClass = i_env->GetObjectClass(nbField);
    jfieldID val = i_env->GetFieldID(longClass, "value", "J");
    if(val == NULL)
         return -899;  
    i_env->SetLongField(nbField, val, (L)l_ul_NbField);
    // nbField is an output value wich is expected to have the value 2 after here !

}

return l_i_Ret; }

此代码返回0但nbField为空! Java来电者

  long nbField = 0 ;
  int l_i_ret = morphoDatabase.getNbField(nbField);
    Log.d("GetNBFields","after getNBFields : "+ nbField + " r : " + l_i_ret );

问题出在代码的这一部分,nbField没有返回l_ul_NbField的值。

1 个答案:

答案 0 :(得分:0)

我找到的解决方案是:

Long nbField = new Long(0);

而不是long