Skip to content
Advertisement

error: JNINativeMethod nfptr throwing invalid conversion from jobjectarray* to void*

I hava following simple jni application:

jobjectArray ListItems(JNIEnv *env, jobject self, jstring library)
{
   jclass c = env->FindClass("java/lang/String");
   jobjectArray a = env->NewObjectArray(2, c, 0);
   env->SetObjectArrayElement(a, 0, env->NewStringUTF("text1"));
   env->SetObjectArrayElement(a, 1, env->NewStringUTF("text2"));
   return a;
}

int main()
{
      ...
      ...*load and initialize Java VM and JNI interface*
      ...
      JNINativeMethod m[1];
      m[0].fnPtr = ListItems;
      m[0].name = "listItems";
      m[0].signature = "(Ljava/lang/String;)[Ljava/lang/String;";
      env->RegisterNatives(myJavaClass, m, 1);
}

when i compile the code as follow it give me “error: invalid conversion from jobjectarray* to void*”

 g++ -I"JNIinclude" -I"JNIincludewin32" test.cpp -o test.exe

Advertisement

Answer

as @Michael said, just need a void* casting:

   int main()
  {
      ...
      ...*load and initialize Java VM and JNI interface*
      ...
      JNINativeMethod m[1];
      m[0].fnPtr =(void*) ListItems;
      m[0].name = "listItems";
      m[0].signature = "(Ljava/lang/String;)[Ljava/lang/String;";
      env->RegisterNatives(myJavaClass, m, 1
  }
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement