Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/402.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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
通过jni向java公开枚举本机类型? 我有C++类,它是从枚举类型派生的。我想使用jni在java中公开这个类中的对象。我已经成功地为类中的所有成员执行了此操作,但枚举类型成员有问题。我用这种方式在java中定义了enum public enum Call { UNDEFINED(-1), INCOMING(1), OUTGOING(2), MISSED(4); private int type; private Call(int type) { this.type = type; } public int type() { return this.type; } } enum Call { UNDEFINED = -1, INCOMING = 1, OUTGOING = 2, MISSED = 4 }; 在C++中以这种方式< /P> public enum Call { UNDEFINED(-1), INCOMING(1), OUTGOING(2), MISSED(4); private int type; private Call(int type) { this.type = type; } public int type() { return this.type; } } enum Call { UNDEFINED = -1, INCOMING = 1, OUTGOING = 2, MISSED = 4 }; < C++中的原始类是 class LogData{ int _id; Call _calltype; long _datetime; int _duration; }_Java_Android_C++_Android Ndk_Java Native Interface - Fatal编程技术网

通过jni向java公开枚举本机类型? 我有C++类,它是从枚举类型派生的。我想使用jni在java中公开这个类中的对象。我已经成功地为类中的所有成员执行了此操作,但枚举类型成员有问题。我用这种方式在java中定义了enum public enum Call { UNDEFINED(-1), INCOMING(1), OUTGOING(2), MISSED(4); private int type; private Call(int type) { this.type = type; } public int type() { return this.type; } } enum Call { UNDEFINED = -1, INCOMING = 1, OUTGOING = 2, MISSED = 4 }; 在C++中以这种方式< /P> public enum Call { UNDEFINED(-1), INCOMING(1), OUTGOING(2), MISSED(4); private int type; private Call(int type) { this.type = type; } public int type() { return this.type; } } enum Call { UNDEFINED = -1, INCOMING = 1, OUTGOING = 2, MISSED = 4 }; < C++中的原始类是 class LogData{ int _id; Call _calltype; long _datetime; int _duration; }

通过jni向java公开枚举本机类型? 我有C++类,它是从枚举类型派生的。我想使用jni在java中公开这个类中的对象。我已经成功地为类中的所有成员执行了此操作,但枚举类型成员有问题。我用这种方式在java中定义了enum public enum Call { UNDEFINED(-1), INCOMING(1), OUTGOING(2), MISSED(4); private int type; private Call(int type) { this.type = type; } public int type() { return this.type; } } enum Call { UNDEFINED = -1, INCOMING = 1, OUTGOING = 2, MISSED = 4 }; 在C++中以这种方式< /P> public enum Call { UNDEFINED(-1), INCOMING(1), OUTGOING(2), MISSED(4); private int type; private Call(int type) { this.type = type; } public int type() { return this.type; } } enum Call { UNDEFINED = -1, INCOMING = 1, OUTGOING = 2, MISSED = 4 }; < C++中的原始类是 class LogData{ int _id; Call _calltype; long _datetime; int _duration; },java,android,c++,android-ndk,java-native-interface,Java,Android,C++,Android Ndk,Java Native Interface,在爪哇 public class LogDataJava{ int _id; Call _callType; long _dateTime; int _duration; } 有没有关于如何在jni级别为枚举类型进行映射的建议?枚举值基本上是枚举类中的静态字段 例如,您可以在jni代码中执行以下操作,将其映射到Java LogData* l = /*...*/ jclass clCall = env->FindClass("LogDataJava$Call"); if

在爪哇

public class LogDataJava{
  int _id; 
  Call _callType;
  long _dateTime;
  int _duration;
}

有没有关于如何在jni级别为枚举类型进行映射的建议?

枚举值基本上是枚举类中的静态字段

例如,您可以在jni代码中执行以下操作,将其映射到Java

LogData* l = /*...*/
jclass clCall = env->FindClass("LogDataJava$Call");
if (l->_callType == Call.UNDEFINED) {
    jfieldID fid = env->GetStaticFieldID(clCall , "UNDEFINED", "LLogDataJava$Call;"); 
} /* else ....*/

jobject callType = env->GetStaticObjectField(cl, fid);
您还可以找到有关静态字段的更多信息