The env pointer is a structure that contains the interface to the JVM. It includes all of the functions necessary to interact with the JVM and to work with Java objects.
Questions tagged [jnienv]
195 questions
4
votes
3 answers
How do I get a JavaVM or JNIEnv from an already-running JVM using JNI?
I am working on a project which involves Rust and Java. I need to be able to use the JNI from the Rust side, without the Java side calling invoking it (because it is not my code). So far, I have been able to ensure my DLL is injected (open a small…

majorsopa
- 75
- 9
4
votes
0 answers
JNI - is there a way to get JNI_OnUnload to be called by the JVM?
There is very little information about this, for example this from 2006, and people giving up on releasing JNI resources gracefully.
JNI_OnUnload (Oracle doc) is meant for releasing resources ("global refs" in particular) when your native…

haelix
- 4,245
- 4
- 34
- 56
4
votes
2 answers
Module path in C++ to Java JNI Call
When I create a Java 8 JVM in C++ I usually use something like the following code to tell JVM the class path:
JavaVMOption* options = new JavaVMOption[1]; // JVM invocation options
options[0].optionString = (char *)"-Djava.class.path=.;./lib2"; …

Vitaliy Tsirkunov
- 453
- 2
- 11
4
votes
3 answers
Calling Java methods from C without starting the JVM from C
I am looking for a tutorial for how to call Java methods from C using JNI. In all the tutorials that I've found so far, the examples show how to first create a JVM from C.
My application starts from Java and uses JNI to call some C functions. I now…

SomethingSomething
- 11,491
- 17
- 68
- 126
4
votes
1 answer
JNI DETECTED ERROR IN APPLICATION: the return type of CallObjectMethodV does not match void android.media.AudioTrack.play()
I am trying to play audio buffer from JNI with AudioTrack
Initilizing AudioTrack object from JNI with below code
jclass AudioTrack = mEnv->FindClass("android/media/AudioTrack");
jclass AudioFormat =…

CLIFFORD P Y
- 16,974
- 6
- 30
- 45
4
votes
1 answer
JNI load jar with dependencies
I am trying to load the following java class in my C++ program using JNI:
package helloWorld;
import org.apache.log4j.Logger;
public class HelloWorld{
private static final Logger logger = Logger.getLogger(HelloWorld.class);
public static…

Victor Silva Do Nascimento
- 281
- 1
- 2
- 5
4
votes
4 answers
Getting Started with JNI and C under Windows
I'm new in Java learning and first time want to get start JNI. And I am working with Cygwin and I have created a file with .java (Helloworld.java) extension as follows:
class HelloWorld {
private native void print();
public static void…

Takianwar
- 41
- 1
- 3
3
votes
0 answers
Loading class from JAR fails when using the JNI in 64-bit C++
I'm trying to load a class contained within a JAR file using the JNI on 64-bit C++ using V2017. I'm able to instantiate a JVM, but the JNI doesn't seem to be able to find the class.
I've tried setting the class path to the directory containing the…

ericc
- 334
- 1
- 14
3
votes
3 answers
Convert JNI -> jobject (basically map and/or map of map in java file) to std::map(c++)
I have a native method in java file:-
class JNITest{
public native void test(String param1, Map param2, Map> param3)
}
After generating header file from java, map is converted to jobject in header…
3
votes
1 answer
Android JNI call method GetStringUTFLength getting crash
Code
std::string abc(const char* param)
{
JNIEnv *pJNIEnv = GetJNIEnv();
//TODO : for testing
jstring jstr = pJNIEnv->NewStringUTF("Ñandú"); //can pass param also
std::string result = convertJStringToString(pJNIEnv, jstr);
…

Nikhil
- 1,023
- 17
- 35
3
votes
1 answer
Pass JNIEnv or Context from Java to Go
I've successfully written a go mobile library and used it from an Android Java app.
I've also successfully called a c function from JNI. This one has the JNIEnv pointer.
I'd like to pass the context/JNIEnv from Java to Go.
Here's where it seems to…

Roy Falk
- 1,685
- 3
- 19
- 45
3
votes
2 answers
Call a function in java from C outside of a JNI function (Android)?
I'm trying to call a Java function from my C code using the JNI in Android, but I'm in a somewhat awkward situation.
My C code is being executed outside of a JNI function in a callback that is passed to a library.
Here is an example of the java…

Nathan F.
- 3,250
- 3
- 35
- 69
3
votes
3 answers
Why does the Android jvm->GetEnv() return the same "env" for multiple threads.?
I'm using jvm->GetEnv(&envThread, JNI_VERSION_1_6) to get the "env" for multple threads in order to make multiple envThread->GetMethodID() calls. Both threads are properly attached to the JVM.
I call the function returned by "GetMethodID()" on the…

Bungles
- 1,969
- 2
- 25
- 54
3
votes
2 answers
android apk JNI report can't find method
well, my app java code as follows:
package doc.android.demo;
public class NativeInterface {
private String mStrCrtMsg;
/** The current file name to be displayed */
private String mStrCrtFileName;
public static final native int…

harris
- 1,473
- 1
- 17
- 26
3
votes
1 answer
JNI in C++ to read file to jbyteArray
I am writing a C++ program in UNIX to generate a shared library which will be called in java using JNI. This C++ program has to read a file in UNIX box then it will have to be converted into jbyteArray (JNI data type) so that JAVA can use it.
I…

Renga
- 119
- 1
- 3
- 12