Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9178533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:34:27+00:00 2026-06-17T17:34:27+00:00

test.c #include <string.h> #include <jni.h> #include <android/log.h> #include <stdio.h> #include <stdlib.h> jstring Java_com_test_b_hello_hellostr( JNIEnv*

  • 0

test.c

#include <string.h>
#include <jni.h>
#include <android/log.h>
#include <stdio.h>
#include <stdlib.h>

jstring Java_com_test_b_hello_hellostr( JNIEnv* env,jobject thiz )
{
    return (*env)->NewStringUTF(env, "Hello from JNI !");
}

This compilation is OK. But compile has the error when I change to test.cpp.

libb/jtest.cpp: In function ‘_jstring* Java_com_test_b_hello_hellostr(JNIEnv*, _jobject*)’:
jtest.cpp:108: error: base operand of ‘->’ has non-pointer type ‘_JNIEnv’
make[1]: * [out/…/obj/SHARED_LIBRARIES/libdrvb_intermediates/jtest.o] Error 1

Why it like this? It has the difference between app and c?

I check the system jni.h file: alps\dalvik\libnativehelper\include\nativehelper\jni.h
.

.
    void        (*ReleaseStringChars)(JNIEnv*, jstring, const jchar*);
    jstring     (*NewStringUTF)(JNIEnv*, const char*);
    jsize       (*GetStringUTFLength)(JNIEnv*, jstring);
...
    jstring NewStringUTF(const char* bytes)
    { return functions->NewStringUTF(this, bytes); }
.....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:34:29+00:00Added an answer on June 17, 2026 at 5:34 pm

    JNI for C++ is slightly different from JNI for plain C.

    In plain C it is correct to use: (*env)->SomeFunction(env, arg, arg, ...)

    Note that you must dereference env and that the first argument to the function is always env.

    In C++, it’s different. You use: env->SomeFunction(arg, arg, ...)

    You don’t need to dereference env and you don’t pass env as the first argument.

    The actual calls into Java will be the same. Java doesn’t care whether you use plain C or C++ to do the JNI stuff.

    Here’s a quick introduction to using C++ for JNI.

    http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/cpp.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include stdlib.h #include stdio.h #include string.h int main(int argc, char* argv[]) { int *test
I have the following test application: #include <stdlib.h> #include <string.h> #include <stdio.h> int main(void){
Here's a minimal test case: #include <stdio.h> #include <stdlib.h> int main ( int argc
So I have the following test code: #include <string.h> #include <stdio.h> int main(int argc,
Let's consider this simple test program: #include <stdio.h> #include <string.h> int main(int argc, char
I have a simple jni function in test.cpp: #include <jni.h> #include <stdio.h> extern C
Below is my code (test.c): #include <stdio.h> #include <string.h> int main(int argc, char **argv)
Having a program like this: #include <iostream> #include <string> using namespace std; class test
I created a program called test: #include<stdlib.h> #include<iostream> int main() { std::cout<<system(..\\add\\debug\\add.exe 4 8);
I'm having trouble running gprof on OS X. The file test.c is: #include <stdio.h>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.