JNI Problem (some C/C++ expertise required please)
Posted on 2005-04-24
I'm just learning to use JNI; I've created a few Shared Libraries, and have successfully linked them in with my Java Program. Now, I decided to start using C++ more for the main Native code (as opposed to C, which I'd been using so far); so, I've gone back to something very basic: The Java program passes a String to the Native function, which then prints it to the screen.
Here's my C++ Code:
using namespace std;
JNIEXPORT void JNICALL Java_Output_print( JNIEnv *env, jobject obj, jstring msg )
const char *str = (*env)->GetStringUTFChars( env, msg, 0 ); // Line 9
string s( str );
(*env)->ReleaseStringUTFChars( env, msg, str ); // Line 11
cout << s << endl;
I am using Dev-C++ for my C/C++ IDE. I've created a New "DLL" Project, and have added the above source (ObjectImp.cpp), and the Object.h Header File to the Project.
However, when I compile it, I'm getting these error messages:
W:\Code\OutputImp.cpp In function `void Java_Output_print(JNIEnv*, _jobject*, _jstring*)':
9 W:\Code\OutputImp.cpp base operand of `->' has non-pointer type `JNIEnv_'
11 W:\Code\OutputImp.cpp base operand of `->' has non-pointer type `JNIEnv_'
W:\Code\Makefile.win [Build Error] [OutputImp.o] Error 1
Why is this happening?? What is wrong with these lines:
const char *str = (*env)->GetStringUTFChars( env, msg, 0 ); // Error (line 9)
(*env)->ReleaseStringUTFChars( env, msg, str ); // Error (line 11)