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

时间:2011-05-16 12:50:06

标签: android java-native-interface 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

知道为什么吗?

1 个答案:

答案 0 :(得分:16)

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

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

使用JNI调用,该调用期望返回JNI对象:

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

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

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