JNI calls the Java method

Source: Internet
Author: User
The method for JNI to call the Java class is similar to that of the reflected code. First obtain the object class. --> Jobject OBJ; jclass CLS = env-> getobjectclass (OBJ); then the query method is jmethodid mgetzoom = env-> getmethodid (CLS, "getzoom ","() I "); jmethodid getfocus = env-> getmethodid (CLS," getdirectionalarrows "," () ljava/util/vector ;"); then use this method ID to execute the OBJ method. Jint I = env-> callintmethod (OBJ, mgetzoom); jobject VEC = env-> callobjectmethod (OBJ, getfocus); Note the format of the getmethodid method. Jmethodid getmethodid (jnienv * ENV, jclass clazz, const char * Name, const char * sig); jnienv is not required in C ++. Clazz is the jclass. Name obtained earlier. It is the method name, and SIG is the method signature. The method signature has a specific format: (param-type) ret-type, which indicates the type of parameters passed in by the method, the following is the return type. param-type and ret-type are both composed of specific symbols. Each Java primitive type has its own corresponding symbols as shown in the following table. Table 3-2 Java VM type signatures type signature Java type Z Boolean B byte C char s short I Int J long F float D Double l fully-qualified-class; fully-qualified-class [type [] (Arg-types) ret-type method type such as long F (int n, string S, int [] ARR ); the signature of IS (iljava/lang/string; [I) J. Do not forget l fully-qualified-class; The; number following this format. PS: You can view the method signature through javap-S <class>.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.