从我的c代码中,我想访问我的字段tasttrigger的值:
public class ApplicationConfigs {
public enum TaskTrigger {
QUEUED, TIMED;
private final int value;
private TaskTrigger() {
this.value = ordinal();
}
public int getValue() {
return value;
}
public static TaskTrigger fromValue(int value)
throws IllegalArgumentException {
try {
return TaskTrigger.values()[value];
} catch(ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("Unknown enum value :"+ value);
}
}
}
private int applicationId;
private TaskTrigger taskTrigger;
...
我的jni代码崩溃了,没有给我太多关于我做错了什么的提示。第一行代码正常工作以检索applicationid。获取tasktrigger对应的int值缺少什么?
JNIEXPORT jlong JNICALL Java_com_example_e2e_MainActivity_run(
JNIEnv *env, jobject callingObject,
jobject app1Configs) {
jclass cls = env->GetObjectClass(app1Configs);
app1ConfigsC.application_id = env->GetIntField(app1Configs, env->GetFieldID(cls, "applicationId", "I")); // works just fine
jmethodID triggerMethod = (env)->GetMethodID( (env)->FindClass(
"com/example/e2e/ApplicationConfigs$TaskTrigger"), "getValue", "()I");
jfieldID fieldId = env->GetFieldID(cls, "taskTrigger", "Lcom/example/e2e/ApplicationConfigs/TaskTrigger;");
jobject objField = env->GetObjectField (app1Configs, fieldId);
jint value = (env)->CallIntMethod(objField,triggerMethod);
更新
我对每个返回值进行了null测试,fieldid为null。我也试过了
jfieldID fieldId = env->GetFieldID(cls, "taskTrigger", "()com/example/e2e/ApplicationConfigs$TaskTrigger;");
但仍然返回空值。
暂无答案!
目前还没有任何答案,快来回答吧!