In JNI Cannot using GetIntField get the value in the java class Android -
I try to get value in native class field mant. This class is made by simple JNI In this sample, I am setting up MINTVALUE 9. Try adding the JNI function using the gateIntfield to get the value of the value. It should add 9 functions. But it seems that GetIntfield can not find the field in this job. How do I get MINT from JNI? Thank you for you comment.
Here is the JNI source code.
static jfieldID gNative; Add Static Jint (JNIEnv * env, Job Case, Zint A, Janet B) {Fine Results = A + B; LOGI ("% d +% d =% d", a, b, result); Int value = env-> GetIntField (Thies, Genetic); Result = value; Return result; } Static const char * classPathName = "com / example / android / simplejni / native"; Stable JNinativeMethod method [] = {{"Add", "(II) I", (Zero *) Addition}}}; Static int registernet methyls (JNINW * AV, CONST FOUR * CLASSNOM, JANENTIVE Methend * GM methods, int Niemaths) {Jacques Claude; Clause = and-> FindClass (classname); If (clazz == NULL) {LOGE ("The original registration class '% s', unable to find className); Return JNI_FALSE;} GNative = env-> GetFieldID (Clause," MINT "," I "); If (en.want.name) (LOG ("mnt field id fail");} if (env-> register navigates (clause, gm method, number method) & lt; 0) {LOGE ("Registered resident Failed for '% s', className); Return JNI_FALSE; } Returned JNI TRUE; } Static Interest Register Netviews (JNINV * NV) {If Registered! Native Maths (NY, ClassPathName, Methods, Sysf (Methods) / Psychophos (Methods [0])) {JNIFLS; } Returned JNI TRUE; } Typeface Federation {JNIEnv * env; Zero * venv; } UnionJNInivatowoid; Jint JNI_OnLoad (Java * vm, void * reserved) {UnionJNIEnvToVoid uenv; Uenv.venv = NULL; Gene results = -1; JNIEnv * env = NULL; LOGI ("JNI_OnLoad"); If (vm-> GetEnv (and amp; uenv.venv, JNI_VERSION_1_4)! = JNI_OK) {LOGE ("Error: GetEnv failed"); Goto bail; } Env = uenv.env; If the registers (envies)! = JNI TRU ("error: register navies failed"); goto bail;} result = JNI_VERSION_1_4; bail: return result;} original class Here the public function set is used to set the mInt value in this class. "public-class" (private int mInt; stable { System.loadLibrary ("simplejni");} Public Zero Settlement (int k) {mInt = k;} Fixed country int sum (int a, int b);} simple ja Follow the I code list.
The public square expands SimpleJNI activity {@ Override Crate on Public Zero (Bundled Saved InstanceState) {super.onCreate (SavedInstanceState); TextView TV = New Textview (this); Native = new origin (); nv.setval (9); int sum = nv.add (2, 3); Tv.setText ("2 + 3 =" + integer .strstring (yoga)) ; SetContentView (TV);}}
Your add function in JNI is incorrect / not Original code
Fixed Add jint (JNIEnv * env, Job Case, Zint A, Janet B) {Fine Results = A + B; LOGI ("% d +% d =% d", a, b, result); Int value = env-> GetIntField (Thies, Genetic); Result = value; Return result; }
The first JNI function signature will be something like this
Java_native_add (JNIEnv * env, jobject thiz < Try to generate a function signature using Strong> javah
Make sure that the point of the add-function is, unless you have written it for testing the JNI code. , Then it would be easy to understand a small example. Anyway it is hopeful that it helps
Comments
Post a Comment