error: undefined reference to '_jstring* QAndroidJniObject::callStaticMethod<_jstring*>(char const*, char const*)'

2.4k views Asked by At

I'm trying to use QAndroidJniObject. As a test I'm just calling 2 Java functions, one returns an int, the other a string.

When returning an int, this code compiles fine:

jint a = QAndroidJniObject::callStaticMethod<jint>("HelloJava", "getInt");

But if I change it to calling a function returning a string, it fails:

jstring b = QAndroidJniObject::callStaticMethod<jstring>("HelloJava", "getString");

It fails with

error: undefined reference to '_jstring* QAndroidJniObject::callStaticMethod<_jstring*>(char const*, char const*)'

Since QAndroidJniObject::callStaticMethod is a template function, how can it be defined for one type but undefined for another?

Edit: Actually, I just tested with jobject, jbyteArray, jbooleanArray, jbyte, jboolean, etc. This is what I found - only the integral number types such as jshort, jint, jlong, jboolean work, while strings, arrays, and objects all give an undefined reference error.

2

There are 2 answers

0
László Papp On BEST ANSWER

As you can see in the following table, the integer types are primitive, whereas the rest are object types. Therefore, I suggest that you try using instead:

jstring b = QAndroidJniObject::callStaticObjectMethod<jstring>("HelloJava", "getString")

This is not a bug, but a feature. See this issue tracker entry on the official stance:

QAndroidJniObject/jstring : no reference

0
mabg On

try this:

 QAndroidJniObject jb = QAndroidJniObject::callStaticObjectMethod("HelloJava", "getString", "()Ljava/lang/String;");
 QString b = jb.toString();