Base operand of ' a ' has non-pointer type ' jnienv {aka _jnienv} ' and method ' Getstringutfchars ' could no

Source: Internet
Author: User

The JNI example of the Android NDK band is using C to define the JNI interface, but in the project, because the native code is written in C + +, I use C + + to define the JNI interface, but beginners always encounter many problems:


Frequently asked questions in JNI:

1, base operand of ' has non-pointer type ' jnienv {aka _jnienv} ' and method ' Getstringutfchars ' could not being resolved

One of the problems with your JNI configuration is whether. cpp or. c Files and:

And


Solution to the problem:

1 "with C + + to write code, the file name must be" cpp "suffix:C + + code must has a. cpp extension., must be CPP suffix, C suffix does not work;2 "Use C to write code, the file name must be" C "suffix;
2. The code that is called is written like this://return (*env)->newstringutf (env, "Hello from JNI!"); /If it is in C language format, this way
//return Env->newstringutf ((char *) "Hello from JNI!"); /c++ in this format


The wrong way:

Online there is a method is as follows, but this method is obviously cheating children, which is useful to ignore this kind of thing, not recommended


The right approach:

The problem is 2nd above, so



This is if you want to delve into the reasons you can view <jni.h>

1. Using the. cpp file to define the

Const char* Getstringutfchars (jstring string, jboolean* iscopy)
{return Functions->getstringutfchars (this, string, iscopy);}


2. Definition with. c file

Const char* (*getstringutfchars) (jnienv*, jstring, jboolean*);


Base operand of ' a ' has non-pointer type ' jnienv {aka _jnienv} ' and method ' Getstringutfchars ' could no

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.