I receive a null pointer exception when I call setTimeStamp method from JNI.I want to populate the array on JNI side .(Array is Array of custom objects)
DataAvailable
public class DataAvailable {
String timestamp;
public void setTimeStamp(String timestamp) {
System.out.println("Timestamp is "+timestamp);
this.timestamp = timestamp;
}
JNIWrapper.java
public native int pax_store_get_data_avail_info(DataAvailable[] stats_array);
JNI Code
JNIEXPORT jint JNICALL Java_demo_JNIWrapper_pax_1store_1get_1data_1avail_1info
(JNIEnv *env, jclass jclass1, jobjectArray jobj){
jclass dataClass=(*env)->FindClass(env,"demo/DataAvailable");//Get the java class
for(i=0;i< 2;i++)
{
jobject j=(*env)->GetObjectArrayElement(env,jobj,i);
jmethodID meth=(*env)->GetMethodID(env,dataClass,"setTimeStamp","(Ljava/lang/String;)V");//this gets the method id present in the class
if(meth==NULL){
printf("Method set is null");
}
jstring x = (*env)->NewStringUTF(env,"2013-12");
(*env)->CallObjectMethod(env,j,meth,x);//This is where I get Null Pointer
}
(*env)->DeleteLocalRef(env, dataClass);
return 0;
}