0

im attempting to build c++ code with ndk-build but i keep getting this error base operand of '->' has non-pointer type 'JNIEnv <aka _JNIEnv>'

i have tried every solution on the first 2 pages of google with no luck, the ndk just isnt being good to me.

nativemain.h

#ifndef NATIVEMAIN_H
#define NATIVEMAIN_H

#include <string.h>
#include <jni.h>

extern "C"
{

JNIEXPORT jstring JNICALL Java_com_ndktest3_MyRenderer_stringFromJNI( JNIEnv* env,
                                                  jobject thiz );
}

#endif

nativemain.cpp

#include <nativemain.h>


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

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := nativemain
LOCAL_SRC_FILES := nativemain.cpp

include $(BUILD_SHARED_LIBRARY)
DevGuy
  • 638
  • 7
  • 18

1 Answers1

0

Try changing your syntax slightly

I believe the error is the miss-use of the '->' operator
"

{
    return env->NewStringUTF("Hello from JNI !");
}

try casting env as a pointer like so

{
    return (*env)->NewStringUTF(env, str);
}

where str is a predefined string such as your hello message.
check this post as a cross reference: Do I need to clean up the char* passed to NewStringUTF?

Community
  • 1
  • 1
Andros
  • 95
  • 8
  • That's actually dereferencing rather than casting. `env` is a pointer to a pointer to a struct, while the `->` operator expects a pointer to a struct, so we have to dereference the outer pointer before using `->` on the remaining pointer to a struct. – Chris Stratton Jun 04 '13 at 17:36