Tag Archives: : operand of ‘->’ has non-pointer type ‘JNIEnv

[Solved] operand of ‘->’ has non-pointer type ‘JNIEnv

Compile the JNI error log:

D:\TVMao\WorkSpace\DramaApp\TestJni>ndk-build
Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersi
on 14 in ./AndroidManifest.xml
[armeabi] Compile++ thumb: test <= test.cpp
jni/test.cpp: In function ‘void Java_com_example_testjni_Decoder_sendIr(JNIEnv*,
jclass, jint, jintArray)’:
jni/test.cpp:27:20: error: base operand of ‘->’ has non-pointer type ‘JNIEnv {ak
a _JNIEnv}’
jni/test.cpp:28:28: error: base operand of ‘->’ has non-pointer type ‘JNIEnv {ak
a _JNIEnv}’
jni/test.cpp:47:8: error: base operand of ‘->’ has non-pointer type ‘JNIEnv {aka
_JNIEnv}’
make.exe: *** [obj/local/armeabi/objs/test/test.o] Error 1

The reason is

Your code uses the C style to access Env and your file is cpp

 

test.cpp

jsize len = (*env)->GetArrayLength(env, pattern);

(*env)->ReleaseIntArrayElements(env, pattern, patternArray, JNI_ABORT);
Solution

1. Change to test.c

2. Change to

int* patternArray = env->GetIntArrayElements(pattern, NULL);

env->ReleaseIntArrayElements(pattern, patternArray, JNI_ABORT);