如何使用 JNI 将 double 和无符号 int 从本机 c 库返回到 java



我是使用 JNI 的新手,所以我正在尝试从 C 中的本机库中获取doubleunsigned int并将值返回到我的 java 端,但我不断收到来自 Android Studio 的以下错误

Error:(111, 37) error: called object type 'double' is not a function or function pointer
Error:(117, 43) error: called object type 'unsigned int' is not a function or function pointer
Error:(220, 19) error: functions that differ only in their return type cannot be overloaded

这是我的代码:

double SuperpoweredExample::getPosition() {
double pos = playerA->positionMs();
return pos;
}
unsigned int SuperpoweredExample::getDuration() {
unsigned int dur = playerA->durationMs();
return dur;
}

而这是外部C结构

JNIEXPORT jdouble Java_com_superpowered_crossexample_MainActivity_getPosition(JNIEnv *javaEnvironment, jobject self) {
return example->getPosition();
}
JNIEXPORT jint Java_com_superpowered_crossexample_MainActivity_getDuration(JNIEnv *javaEnvironment, jobject self) {
return example->getDuration();
}

拜托伙计们,我将不胜感激任何帮助... 提前谢谢你

你并没有完全费心提供完整的类定义,或者回答你在评论中被问到的问题,但似乎

playerA->positionMs

是数据成员,而不是成员方法,对于其他方法调用也是如此。因此,不能将它们作为方法调用。但是您可以直接将它们作为值返回。

最新更新