我想在本机c代码中读取java类的元素。
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
& valueY
字段。
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);
}
}
但我得到错误,如下所示
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 WARNING?
是什么意思。怎么解决?
答案 0 :(得分:1)
no field with name='valueX' signature='D' in class [Lcom/jjoe64/graphview/GraphView$GraphViewData;
注意班级名称中的'['。您正在寻找数组类valueX
中名为GraphViewData[]
的字段,而不是类GraphViewData
。
也许您打算将inData
而不是data
传递给GetObjectClass
?