Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 682
sashoalm Avatar asked Dec 06 '14 11:12

sashoalm


2 Answers

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

like image 139
lpapp Avatar answered Oct 31 '22 00:10

lpapp


try this:

 QAndroidJniObject jb = QAndroidJniObject::callStaticObjectMethod("HelloJava", "getString", "()Ljava/lang/String;");
 QString b = jb.toString();
like image 34
mabg Avatar answered Oct 30 '22 23:10

mabg