• Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI newbie - different const qualifiers

 
Gus Spain
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody, this is is my first time using jni and i�m getting a few warnings which i would like to fix if possible.
I have this C function, Getdata (char * Getdata(char *q, char *t)) and i want to send its return value to the java side doing this

JNIEXPORT void JNICALL Java_DBtools_execute_1upd
(JNIEnv *env, jobject obj, jstring query, jstring table)
{
const char *query_c = (*env)->GetStringUTFChars(env, query, 0);
const char *table_c = (*env)->GetStringUTFChars(env, table, 0);

jclass cls = (*env)->GetObjectClass(env, obj);
jmethodID mid = (*env)->GetMethodID(env, cls, "print_upd",
"(Ljava/lang/String;Ljava/lang/String V");
if (mid == 0) {
return;
}
(*env)->CallVoidMethod(env,obj,mid,
(*env)->NewStringUTF(env,Getdata(query_c,table_c)),
(*env)->NewStringUTF(env,get_writeset()));
}

but i get two warnings (warning C4090) saying that there are different const qualifiers and it points to the CallVoidMethod line, because of query_c and table_c variables. Is this an important warning? How do i fix it?
Thanks!

[ November 24, 2004: Message edited by: Gus Spain ]
[ November 24, 2004: Message edited by: Gus Spain ]
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The signature of your Getdata method is
char* Getdata(char* , char*).

The problem that the compiler is warning about is that the parameters are char*, but you are passing const char*.

To relieve this, simply remove the const qualifier in the JNI function; cast to a (char*) if needed.
[ November 24, 2004: Message edited by: Joel McNary ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!