Issue
I am trying to build a program using Android Studio1.3.2 + NDK + Windows7. I want to pass a string from Java function to Native C function (const char*).
The native C function declaration is:-
public native int HRFromJNI(String path);
The Java function call is:-
tv.setText(String.valueOf(HRFromJNI(path)));
The Native C function is:-
extern "C" {
JNIEXPORT jint JNICALL
Java_com_example_hellojni_HelloJni_HRFromJNI
(JNIEnv *env, jobject obj,jstring path)
{
int HRval = 0;
char *Path;
Path = (*env)->GetStringUTFChars( env, path, null) ;
HRval = filefunction(Path);
return HRval;
}
The function called by the Native C function is :-
int filefunction(char* filename)
{
FILE* file = fopen((char*)filename,"w+");
//Reads value from the file and returns it.
.
.
.
}
But i get error "Base operand of -> has non-pointer type JNIEnv{aka _JNIEnv}"
Is this the correct way of passing string to Native C code, or is there any other way to assign a string from Java to const char* ?
Solution
Change below line:
Path = (*env)->GetStringUTFChars( env, path, null) ;
To:
Path = env->GetStringUTFChars( env, path, JNI_TRUE) ;
Pass jni boolean variable, instead of passing null.
Answered By - Saritha G
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.