I am not familiar with Java when I first came into contact with JNI. I have encountered some problems due to the android project.
The Java code is as follows:
Class {
Static {
System. loadlibrary ("");
}
Int A = 1;
Class B {
Int B = 2;
Public void show (){
System. Out. println ("B =" + B );
}
};
Public native B getb ();
Public void show (){
System. Out. println ("A =" + );
Getb (). Show ();
}
};
As shown in the above Code, a has an internal class B. If you want to return the instance of B in the JNI layer, first use javap-s-p A. B to view the signature.
A $ B ();
Signature: (La;) V
The constructor B has a parameter Class.
The C code is as follows:
Jniexport jobject jnicall java_a_getb (jnienv * ENV, jobject thiz)
{
Jobject B = NULL;
Jclass bcls = (* env)-> findclass (ENV, "A $ B ");
Jmethodid mid = (* env)-> getmethodid (ENV, bcls, "<init>", "(La;) V ");
B = (* env)-> newobject (ENV, bcls, mid, thiz );
Return B;
}
Note the red code above. Because B is the internal class of A, the findclass is a $ B.
Then the construction method of B. Because it is the construction method, the third parameter of getmethodid is fixed as "<init>" and the fourth parameter, which is "() for general classes "() V ",
Because B is an internal class of A, you can see through the javap above that it should be "(La;) V"