Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - Method NewStringUTF() could not be resolved

Tags:

android

opencv

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?

like image 334
user2261269 Avatar asked Apr 09 '13 10:04

user2261269


2 Answers

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.

like image 97
DeltaCap019 Avatar answered Oct 01 '22 11:10

DeltaCap019


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.

like image 43
John E Avatar answered Oct 01 '22 12:10

John E