- C/C++ code
//cpp文件代码如下: #include <stdio.h> #include "java2dll.h" JNIEXPORT jstring JNICALL Java_Java2dll_cTrim(JNIEnv *env, jobject obj, jstring str) { const char* strTemp; strTemp=env->GetStringUTFChars(env,str,NULL); if(strTemp==NULL) { return NULL; } cTrim(strTemp); return env->NewStringUTF(env,strTemp); env->ReleaseStringUTFChars(env,str,strTemp); } //.h文件代码如下:/* DO NOT EDIT THIS FILE - it is machine generated */#include <jni.h>/* Header for class Java2dll */#ifndef _Included_Java2dll#define _Included_Java2dll#ifdef __cplusplusextern "C" {#endif/* * Class: Java2dll * Method: cTrim * Signature: (Ljava/lang/String;)Ljava/lang/String; */JNIEXPORT jstring JNICALL Java_Java2dll_cTrim(JNIEnv *, jobject, jstring);#ifdef __cplusplus}#endif#endif
报错如下:
Compiling...
java2dll.cpp
E:\vcÏîÄ¿\java2dll\java2dll.cpp(8) : error C2660: 'GetStringUTFChars' : function does not take 3 parameters
E:\vcÏîÄ¿\java2dll\java2dll.cpp(15) : error C2065: 'cTrim' : undeclared identifier
E:\vcÏîÄ¿\java2dll\java2dll.cpp(17) : error C2660: 'NewStringUTF' : function does not take 2 parameters
E:\vcÏîÄ¿\java2dll\java2dll.cpp(19) : error C2660: 'ReleaseStringUTFChars' : function does not take 3 parameters
Ö´ÐÐ cl.exe ʱ³ö´í.
java2dll.obj - 1 error(s), 0 warning(s)
这在网上找的一个例子,情况和我要做的事情一样,可惜就是这段代码不通。
网址是http://wallimn.iteye.com/blog/647409
大概就是说我的代码参数不对,还有就是那个方法未定义,可是,我不是在.h里面已经定义了吗?求高手:
------解决方案--------------------------------------------------------
给方法换换位置呗,再试试。