Reputation: 1506
I want to read the elements of a java class in native c code.
Java class is as below
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;
}
}
I am passing an array of this class to native function, and trying to read the valueX
& valueY
fields.
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)
What i am doing wrong, also, what is the meaning of JNI WARNING?
. How to solve it?
Upvotes: 0
Views: 1166
Reputation: 52343
no field with name='valueX' signature='D' in class [Lcom/jjoe64/graphview/GraphView$GraphViewData;
Note the '[' in the class name. You're looking for a field called valueX
in the array class GraphViewData[]
rather than the class GraphViewData
.
Perhaps you meant to pass inData
rather than data
to GetObjectClass
?
Upvotes: 2