0

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"JNI\include" -I"JNI\include\win32" test.cpp -o test.exe
payam abdy
  • 43
  • 5
  • Can't you just cast it to `void*`? Note that it comes with some caveats, see e.g. https://stackoverflow.com/questions/60064078/portability-of-jni-native-function-registration-via-registernatives-in-c-on – Michael Dec 13 '20 at 10:12

1 Answers1

0

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
  }
payam abdy
  • 43
  • 5