Android的JNI阅读jobjectArray场失败 [英] android jni reading jobjectArray field fails
本文介绍了Android的JNI阅读jobjectArray场失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想读一个java类的本机C code中的元素。
I want to read the elements of a java class in native c code.
Java类是如下
static public class GraphViewData implements GraphViewDataInterface {
public final double valueX;
public final double valueY;
public GraphViewData(double valueX, double valueY) {
super();
this.valueX = valueX;
this.valueY = valueY;
}
@Override
public double getX() {
return valueX;
}
@Override
public double getY() {
return valueY;
}
}
我传递这个类本机函数的数组,并试图阅读 valueX
&安培; VALUE年
字段。
int Java_com_example_fftplot_PlotActivity_computeFFT(JNIEnv *env, jobject thiz,jint function,jobjectArray data) {
int i;
jsize inLength = (*env)->GetArrayLength(env,data); //size of input object array
for(i = 0; i < inLength/8 ; i++){
jobject inData = (*env)->GetObjectArrayElement(env,data,i);
jclass inDataClass = (*env)->GetObjectClass(env,data);
jfieldID inXval = (*env)->GetFieldID(env,inDataClass,"valueX","D");
jfieldID inYval = (*env)->GetFieldID(env,inDataClass,"valueY","D");
__android_log_print(ANDROID_LOG_ERROR, "inXval =", "%l",inXval);
__android_log_print(ANDROID_LOG_ERROR, "inYval =", "%l",inYval);
}
}
但我得到的错误,如下
But i get error , as below
01-25 17:29:15.780: W/dalvikvm(3958): JNI WARNING: JNI method called with exception pending
01-25 17:29:15.780: W/dalvikvm(3958): in Lcom/example/fftplot/PlotActivity;.computeFFT:(I[Lcom/jjoe64/graphview/GraphView$GraphViewData;)I (GetFieldID)
01-25 17:29:15.780: W/dalvikvm(3958): Pending exception is:
01-25 17:29:15.790: I/dalvikvm(3958): java.lang.NoSuchFieldError: no field with name='valueX' signature='D' in class [Lcom/jjoe64/graphview/GraphView$GraphViewData;
01-25 17:29:15.790: I/dalvikvm(3958): at com.example.fftplot.PlotActivity.computeFFT(Native Method)
我在做什么错了,还等什么是 JNI警告的含义是什么?
。如何解决呢?
推荐答案
与NAME ='valueX'类的签名='D'没有字段[LCOM / jjoe64 / graphview / GraphView $ GraphViewData;
请注意在类名的'['。你正在寻找一个名为 valueX
中的数组类 GraphViewData []
字段而不是类 GraphViewData code>。
Note the '[' in the class name. You're looking for a field called valueX
in the array class GraphViewData[]
rather than the class GraphViewData
.
也许你的意思是通过 INDATA
,而不是数据
到 GetObjectClass
?
Perhaps you meant to pass inData
rather than data
to GetObjectClass
?
这篇关于Android的JNI阅读jobjectArray场失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文