Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cast from jobject to jboolean loses precision

I am trying to cast jobject to jboolean

    jmethodID mGet = env->GetMethodID(cJsonObjClass, "get","(Ljava/lang/String;)Ljava/lang/Object;");    
    jboolean val = (jboolean)env->CallObjectMethod(object, mGet , key);

getting this compile error:

cast from 'jobject {aka _jobject*}' to 'jboolean {aka unsigned char}' loses precision [-fpermissive]

what does it mean and what to do?

like image 200
Dania Delbani Avatar asked Sep 11 '15 07:09

Dania Delbani


1 Answers

For anyone else who gets the error while using CallObjectMethod

error: cast from pointer to smaller type 'jboolean' (aka 'unsigned char') loses information

The correct way to call a method which returns a boolean ist to use CallObjectMethod

So the answer here is:

change

 jboolean val = (jboolean)env->CallObjectMethod(object, mGet , key);

to

jboolean val = (jboolean)env->CallBooleanMethod(object, mGet , key);
like image 141
foxy Avatar answered Sep 30 '22 08:09

foxy