Skip to content Skip to sidebar Skip to footer

Call Java Function From C++ Method

I am facing trouble calling a Java function from C++ method. The following is what I am doing My java class package com.q.IT; public class Carv { public boolean isValidRatio(floa

Solution 1:

As an example, check Creating a JVM from C. It shows a sample procedure to create a JVM and invoke a method. If the JVM already exists; e.g. your C program is invoked by the Java program (callback situation), you can cache the JNIEnv* pointer.

As an advice, be careful caching pointers to the JVM from C/C++, there are some semantics involved as to what you can cache and it could be invoked later on.

Source: How to call Java functions from C++?

Solution 2:

Your pointer isn't initialized :

JNIEnv *env;
jclass ItClass =env->FindClass("com/q/IT/Carv"); // env has not been set

You have to use the JNIEnv pointer that you get from the JNI call if you want to be able to communicate with your Java code.

Post a Comment for "Call Java Function From C++ Method"