JNI Warnig期望返回类型'L'调用LocationManager.requestLocationUpdates

QLa*_*nds 8 java-native-interface android android-ndk

我正在使用Necessitas(Android中的QT).基本上,使用Andrid NDK,android活动会调用QT应用程序(.so).

我正在研究GPS的一些绑定.我想我到了那里,但是当我调用方法requestLocationUpdates(String,Long,Float,LocationListener)时,我得到了JNI警告(JNI Warnig期望返回类型'L').

以下是一些代码:

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
Run Code Online (Sandbox Code Playgroud)

知道为什么吗?

小智 16

您正在调用返回"void"的方法:

midConstListener = currEnv->GetMethodID(listenerClass, "<init>", "()V");
Run Code Online (Sandbox Code Playgroud)

使用期望返回JNI对象的JNI调用:

// BAD
currEnv->CallObjectMethod(jSystemServiceObj,midRequestLocationUpdates,StringArg,(jlong)1000,(jfloat)10,jListenerObj);
Run Code Online (Sandbox Code Playgroud)

您应该使用期望返回void的JNI调用:

// GOOD
currEnv->CallVoidMethod(jSystemServiceObj,midRequestLocationUpdates,StringArg,(jlong)1000,(jfloat)10,jListenerObj);
Run Code Online (Sandbox Code Playgroud)