Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 获得;冲突类型错误“;在JNI中使用C_C++_C_Types_Java Native Interface - Fatal编程技术网

C++ 获得;冲突类型错误“;在JNI中使用C

C++ 获得;冲突类型错误“;在JNI中使用C,c++,c,types,java-native-interface,C++,C,Types,Java Native Interface,我试图做到这一点: #include <stdio.h> #include <jni.h> #include "callJNITest.h" JNIEXPORT jint JNICALL Java_callJNITest_displayHelloWorld (JNIEnv env, jclass jcls) { printf("Hello World!"); return 1; } 但是 很好。 我的问题是如何在JNI中声明返回类型?谢谢 根据我的

我试图做到这一点:

#include <stdio.h>
#include <jni.h>
#include "callJNITest.h"

JNIEXPORT jint JNICALL Java_callJNITest_displayHelloWorld
  (JNIEnv env, jclass jcls) {
    printf("Hello World!");
    return 1;
}
但是

很好。
我的问题是如何在JNI中声明返回类型?谢谢

根据我的评论创建答案,因为它解决了OP的问题

头文件包含一个声明,其中
Java\u callJNITest\u displayHelloWorld
的第一个参数的类型是
JNIEnv*
,而在cpp文件中它的类型是
JNIEnv

修复方法是将cpp文件中的
env
类型更改为
JNIEnv*
,以便与头文件中的声明相匹配。

callJNITest.h中有什么?/*不要编辑此文件-它是机器生成的*/#include#ifndef#include(callJNITest#定义)include(callJNITest#ifdef)cpluplus外部“C”{#endif JNIEXPORT jint JNICALL Java_callJNITest_displayHelloWorld(JNIEnv*,jclass);#ifdef(uu cplusplus)#endif#endifLooks就像您在cpp文件中使用JNIEnv for env一样,当它应该是JNIEnv时*
JNIEXPORT void JNICALL Java_callJNITest_displayHelloWorld
  (JNIEnv env, jclass jcls) {
    printf("Hello World!");
    return;
}
JNIEXPORT JNICALL Java_callJNITest_displayHelloWorld
  (JNIEnv env, jclass jcls) {
    printf("Hello World!");
    return;
}