9

I am working on a simple OpenCV code to display an image after undergoing sobel operation. I have included all the necessary paths to the Project Properties for including the OpenCV4Android folder. I resolved all the errors except one:

Error: Method NewStringUTF() could not be resolved

I included <jni.h> I have also included AndroidNDK folder in the project paths. My Eclipse is highly unpredictable. Earlier, it worked fine when i developed other application on Android. Is eclipse machine dependent? What can i do to fix this error?

Arun C
  • 9,035
  • 2
  • 28
  • 42
user2261269
  • 91
  • 1
  • 1
  • 3

4 Answers4

24

Chances are that you are using C syntax in CPP file

I had the same error

Just switch to the right syntax and Problem will be solved C syntax

return (*env)->NewStringUTF(env, "Hello from JNI !");

C++ Syntax

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

After switching from C to C++ syntax my problem got solved.

DeltaCap019
  • 6,532
  • 3
  • 48
  • 70
13

I had this issue. Based on my "solution," it seems to be something funny going on in Eclipse, since I had another project open with (as far as I was able to tell) the exact some properties, paths, etc., besides for being labeled a Library Project.

Just by observing the corresponding struct in jhi.h, the callback prototypes are all there! Ctrl-click the include statement and Eclipse will even link you the reference!

Go to the project's Properties -> C/C++ General -> Code Analysis. Click the "Use project settings" radio button (or "Configure Workspace Settings..." button). Disable (uncheck) the "Method cannot be resolved" checkbox. Click "Apply," "OK." Then for your project, refresh, clean, refresh, build.

There must have been something I did differently in creating the new project. Or maybe it was because of the locations of the projects, or the fact that the previous was a Library. Maybe it really is an Eclipse bug? For reference, I'm using ADT v21.1.0-569685 and NDK r8e for Windows.

John E
  • 193
  • 1
  • 13
3
JNIEXPORT jstring JNICALL Java_com_example_faceextractiontest_Makeover_hello(JNIEnv* env, jobject obj){
const char* c = "hello how are you i am ahmad raza";
jstring s = env->NewStringUTF(c);

return s;
}

This worked for me

ahmad raza
  • 111
  • 1
  • 2
0
  • Step 1: Project Properties -> C/C++ General -> Path and Symbols

  • Step 2: Select 'include' tab, Add -> $ANDROID_NDK_HOME/platforms/android-19/arch-arm/usr/include(Your own path) then, Check 'All languages'

  • Step 3: Apply -> OK

That's it. My solution.

user3094830
  • 1
  • 1
  • 1