androidc++qtjava-native-interfaceqtandroidextras

Passing long value to Java with JNI


I'm trying to pass object pointer as long from C++ code to java method through JNI to convert it back to pointer in callback later.

void Client::process()
{
    long thisAddress = (long)this;
    QAndroidJniObject res = activity.callObjectMethod("process", "(Ljava/lang/Long;)Ljava/lang/String;", (jlong)thisAddress);
}

Java function prototype is public String process(Long clientAddr) and here is beauty that JVM prints to me: Invalid indirect reference 0x5f3d9bc8 in decodeIndirectRef.

What is wrong with this code? Or, maybe, there is another method to do what I want?


Solution

  • Ok. I managed to fix my problem by replacing Float to float using short signature "J" instead, as @Nejat suggested.

    So now it looks like that Qt:

    QAndroidJniObject res = activity.callObjectMethod("process", "(J)Ljava/lang/String;", (jlong)thisAddress);
    

    Java:

    public String process(long clientAddr)