Search code examples
androidjava-native-interfaceandroid-ndk

JNI Warnig expected return type 'L' calling LocationManager.requestLocationUpdates


I am using Necessitas (QT in Android). Basically, using the Android NDK an android activity calls a QT application (.so).

I am working on some bindings for the GPS. I think I am getting there, however I getting a JNI WARNING (JNI Warning expected return type 'L') when I call the method requestLocationUpdates(String, Long, Float, LocationListener).

Here is some of the code:

midGetSystemService = currEnv->GetMethodID(actClass,"getSystemService","(Ljava/lang/String;)Ljava/lang/Object;");

jSystemServiceObj = currEnv->CallObjectMethod(currAct,midGetSystemService,StringArg);

midRequestLocationUpdates = currEnv->GetMethodID(locManClass,"requestLocationUpdates","(Ljava/lang/String;JFLandroid/location/LocationListener;)V");


midConstListener = currEnv->GetMethodID(listenerClass, "<init>", "()V");
jListenerObj = currEnv->NewObject(listenerClass, midConstListener);


currEnv->CallObjectMethod(jSystemServiceObj,midRequestLocationUpdates,StringArg,(jlong)1000,(jfloat)10,jListenerObj);  --->Here is the warning

Any idea why?


Solution

  • You are calling a method that returns "void":

    midConstListener = currEnv->GetMethodID(listenerClass, "<init>", "()V");
    

    using a JNI call that expects in return a JNI object:

    // BAD
    currEnv->CallObjectMethod(jSystemServiceObj,midRequestLocationUpdates,StringArg,(jlong)1000,(jfloat)10,jListenerObj);
    

    You should instead use the JNI call that expects void in return:

    // GOOD
    currEnv->CallVoidMethod(jSystemServiceObj,midRequestLocationUpdates,StringArg,(jlong)1000,(jfloat)10,jListenerObj);