N
Neena
Hi
I have a java code, which calls my native method setvalue. the setvalue
function receives values from my java code and the values are of type
java.lang.object.the value may be String, Long. Integer, byte[] etc.
the native method receives the value as jobject.my native call makes
another call to set the value and for this i have to convert the
jobject to a void pointer. i just make a direct casting.and the value
gets printed before and after casting are the same.
then from java i make a call to my native method getValue. getValue
makes another call and from there getValue receive the value as a
voidpointer. in Getvalue i have to convert this to a bytearray and then
return to my java call. in java i have to convert this to Object and
return to the application.
And my problem is i have passed a Long value( Long l=new Long(1); ) to
my setValue function. and my getValue returns unexpected value...what i
get back is not the value i've set..
what may be the problem?
my code:
setValue:
JNIEXPORT jboolean JNICALL Java_SetName_setValue
(JNIEnv *env, jobject obj, jobject nameValue)
{
printf("Name value in c, %x",nameValue);
return UpperLayerCall_SetValue((PVOID)nameValue);
//PVOID: void pointer
}
getValue:
JNIEXPORT jbyteArray JNICALL
Java_GetName_getValue
(JNIEnv *env, jobject obj, jint valueID, jlong valueLength)
{
PVOID nameValue = NULL; //void pinter..it is memory allocated
jbyteArray nameValueArray = NULL;
UpperLayerCall_GetValue( (int)valueID), nameValue);
//after this call nameValue will contain value we have set earlier
nameValueArray = (*env)->NewByteArray(env, valueLength);
(*env)->SetByteArrayRegion(env, nameValueArray, 0, valueLength,
nameValue);
return nameValueArray ;
}
I have a java code, which calls my native method setvalue. the setvalue
function receives values from my java code and the values are of type
java.lang.object.the value may be String, Long. Integer, byte[] etc.
the native method receives the value as jobject.my native call makes
another call to set the value and for this i have to convert the
jobject to a void pointer. i just make a direct casting.and the value
gets printed before and after casting are the same.
then from java i make a call to my native method getValue. getValue
makes another call and from there getValue receive the value as a
voidpointer. in Getvalue i have to convert this to a bytearray and then
return to my java call. in java i have to convert this to Object and
return to the application.
And my problem is i have passed a Long value( Long l=new Long(1); ) to
my setValue function. and my getValue returns unexpected value...what i
get back is not the value i've set..
what may be the problem?
my code:
setValue:
JNIEXPORT jboolean JNICALL Java_SetName_setValue
(JNIEnv *env, jobject obj, jobject nameValue)
{
printf("Name value in c, %x",nameValue);
return UpperLayerCall_SetValue((PVOID)nameValue);
//PVOID: void pointer
}
getValue:
JNIEXPORT jbyteArray JNICALL
Java_GetName_getValue
(JNIEnv *env, jobject obj, jint valueID, jlong valueLength)
{
PVOID nameValue = NULL; //void pinter..it is memory allocated
jbyteArray nameValueArray = NULL;
UpperLayerCall_GetValue( (int)valueID), nameValue);
//after this call nameValue will contain value we have set earlier
nameValueArray = (*env)->NewByteArray(env, valueLength);
(*env)->SetByteArrayRegion(env, nameValueArray, 0, valueLength,
nameValue);
return nameValueArray ;
}