JNI: Long-object created with wrong value
Posted
by Torbjörn Eklund
on Stack Overflow
See other posts from Stack Overflow
or by Torbjörn Eklund
Published on 2009-07-16T15:03:41Z
Indexed on
2010/03/17
1:01 UTC
Read the original article
Hit count: 457
Hi!
I am writing a c-jni function in Android, and I am having problems with creating a Long-object. I have succeeded in calling the constructor, but when I read the value of the object with longValue, I get the wrong result.
jmethodID longConstructor;
jmethodID longGetLongValue;
jclass cls;
jobject obj;
// Create a object of type Long.
cls = (*env)->FindClass(env,"java/lang/Long");
longConstructor = (*env)->GetMethodID(env,cls,"<init>","(J)V");
obj = (*env)->NewObject(env, cls, longConstructor, 4242);
// Get the value by calling the function longValue.
longGetLongValue= (*env)->GetMethodID(env,cls,"longValue","()J");
long return_long_value = (*env)->CallLongMethod(env, obj, longGetLongValue);
// Log the result.
LOGD("%li", return_long_value);
I would expect that the above code would print 4242 in the log, however the value that is printed in the log is 1691768.
Does anybody have an idea on why 4242 is not written in the log?
© Stack Overflow or respective owner