I am trying to send an integer value from the jni c code to a java function. But as I try to do this , JVM crashes. I don't know the reason. Following codes tell how I have been trying to achieve this.
Java Code :
class Tester {
public native void func();
public native void func_1(Tester T);
public native void func_2(String S);
public static void main(String args[]) {
Tester tester = new Tester();
tester.func();
}
public void printInteger(int x) {
System.out.println(x);
}
static {
System.loadLibrary("DailyTesters");
}
}
JNI C Code:
#include <stdio.h>
#include "Tester.h"
void Java_Tester_func
(JNIEnv *env, jobject obj) {
jclass cls = (*env)->GetObjectClass(env,obj);
jmethodID mid = (*env)->GetMethodID(env,cls,"printInteger","(I)V");
jvalue *a1;
a1->i = 2;
(*env)->CallVoidMethodA(env,obj,mid,a1);
}
What mistake have I made ?