description of the Android JNI Getfieldid and Getmethodid functions
Getfieldid is to get the parameters in the Java class Id,getmethodid get the IDs of the methods in the Java class, which can only invoke parameters or methods declared as public in the class. Use the following:Jfieldid Topicfieldid= env->getfieldid(ObjectClass,"Name","Ljava/lang/string;");
Jmethodid Getcname=env (Objectclass "Getcatname" , "() ljava/lang/string;" ;
< BR style= "Line-height:normal; Word-wrap:break-word; " >
The first parameter is a Java class object. The second parameter is the parameter (or method name), and the third parameter is the signature of the parameter (or method). The third parameter is obtained by the following method.
For example:
Class
Public class Cat{
Private intCatnumber;
String CatName;
PublicCat(intIString Name)
{Catnumber=i; catname=name;}
PublicString Getcatname()
{return This.CatName;}
PublicvoidSetcatname(String CatName)
{ This.=catname}
}
For example, view The Cat class enters the cat's directory with Javac Cat.java to compile and then enter the command:
javap–s cat
The signature of the Cat Method Getcatname is () the parameter in the Ljava/lang/string,cat class is private so it has no signature.
Description of the Android JNI Getfieldid and Getmethodid functions