【问题标题】:JNI Warnig expected return type 'L' calling LocationManager.requestLocationUpdatesJNI 警告预期返回类型“L”调用 LocationManager.requestLocationUpdates
【发布时间】:2011-05-16 12:50:05
【问题描述】:

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

我正在为 GPS 做一些绑定。我想我到了那里,但是当我调用 requestLocationUpdates(String, Long, Float, LocationListener) 方法时,我收到了 JNI WARNING (JNI Warning expected return type '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

知道为什么吗?

【问题讨论】:

  • 嗨,这是因为我需要调用 CallVoidMethod 而不是 CallObjectMethod。对不起这个愚蠢的问题.....我累了:-(卡洛斯。

标签: android java-native-interface android-ndk


【解决方案1】:

你正在调用一个返回“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);

【讨论】:

  • 就我而言activity.callMethod&lt;void&gt;("setRequestedOrientation", "(I)V", 0);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-11
  • 1970-01-01
  • 2020-02-09
  • 2017-11-12
  • 2012-05-04
相关资源
最近更新 更多