Questions tagged [jnienv]

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.

195 questions
39
votes
1 answer

Keeping a global reference to the JNIEnv environment

I am storing off JNIEnv in a global so I can call static java methods later. But is it nessasary to store off a global pointer to the JNIEnv, they way one would with any other java object, or is it a special case that does not require this. JNIEnv*…
weston
  • 54,145
  • 21
  • 145
  • 203
14
votes
1 answer

JNI thread model?

When I call a C/C++ from Java, is a new thread created by JavaVM or JNI to run the C/C++ code while my Java thread is waiting? I ask this because my C/C++ code runs something on the GPU and I need to check a specific buffer to get the result back.…
Hossein
  • 1,152
  • 1
  • 16
  • 32
9
votes
2 answers

What is the best way to save JNIEnv*

I have an Android project with JNI. In the CPP file which implements a listener class, there is a callback x() . When x() function is called, I want to call another function in a java class. However, in order to invoke that java function, I need to…
lyc001
  • 777
  • 1
  • 10
  • 25
8
votes
1 answer

JNI_CreateJavaVM() terminates with exit code 1

I'm trying to call a Java method from C++ using JNI. To do that I've installed jdk1.7.0_51, linking against jdk1.7.0_51\lib\jvm.lib, including jdk1.7.0_51\include and jdk1.7.0_51\include\win32. using the following code in Visual Studio 2012 I tried…
Constantin
  • 8,721
  • 13
  • 75
  • 126
8
votes
2 answers

Caching JNI objects and thread-safety (in Android)

I'm writing a C++ app with native threads (pthreads) and I need to call some Java methods etc. I'm not sure which JNI objects can be safely cached ie stored in my C++ object for use later, possibly/probably by a different thread. I do know that if…
realh
  • 962
  • 2
  • 7
  • 22
7
votes
1 answer

Android JNI Error: NoSuchMethodError: no non-static method

What I'm trying to do is simplified below. Java -> Call C++ function A C++ function A calls C++ function B C++ function B calls Java method C I have to store JVM(2) and global jobject(3). But at part 3, JNI DETECTED ERROR IN APPLICATION: JNI…
김선달
  • 1,485
  • 9
  • 23
6
votes
1 answer

Xamarin.Android binding Call java Object method

I created java binding library via visual studio extension called Xamarin.GradleBinding. I added ru.rambler.android:swipe-layout:1.0.14 package and while using its SwipeLayout, it all works well. But unfortunately it did not created corresponding C#…
mister_giga
  • 560
  • 1
  • 15
  • 37
6
votes
2 answers

jni call to getClass returns null for a jobject

I am facing issues with making a java call from C++ code using JNI. I am able to get the jobject, but the invoocation of any API on the jobject fails. On digging for nearly one day and comparing with other working Java API (jobjects which i call in…
Gaurav Abbi
  • 645
  • 9
  • 23
5
votes
1 answer

How to use JNI_CreateJavaVM to run modular java app

I'm porting our native windows app launcher from Java 8 to Java 11. We used to call JNI_CreateJavaVM method to instantiate a JVM instance, find main class and call its main method. With a modular app, env->FindClass doesn't return our app class. I…
5
votes
0 answers

Are Java Strings stored differently in heap based on how they are being constructed?

I'm working on a code base which uses JNI techniques for modeling native methods. Here is the segment of the native peer method used for java.lang.String#equals(Object) @MJI public boolean equals__Ljava_lang_Object_2__Z (MJIEnv env, int objRef, int…
Gayan Weerakutti
  • 11,904
  • 2
  • 71
  • 68
5
votes
1 answer

How to call Java API's from Native C/C++ in Android

There are lot of examples that Android C/C++ native calls Java APIs. However, all of these examples I have read are the Android Java APIs call native first and then the native calls other Java APIs by using the passed JNI-ENV. Without the passed…
kumar
  • 77
  • 7
5
votes
1 answer

Unable to load .so library files when making a system application

I have created an application which will be a System Application. When I install the application normally(not as system application) ".so" files are getting loaded. But when I'm making it a system application by putting the apk into /system/app/ ,…
mn0102
  • 839
  • 1
  • 12
  • 25
5
votes
2 answers

C++ application with JNI throws an error "jvm.dll not found . re-installing the application could fix ...."

I have written a plain C++ application in VC6 that is using jni to call up a method in java. For doing so, I have included jni.h and other lib folders in the project directories. the code compiles but when i run teh application it fails saying…
user1821083
  • 71
  • 1
  • 5
5
votes
3 answers

what is wrong with this call to the java method?

I am trying to call a Java method from the code. C code listens to either Escape, Shift, Ctrl key press, then it calls the Java method telling which key was pressed. Following are the snippets that play a role in this. C Snippet: mid =…
Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328
4
votes
1 answer

Java binding for C library(GPIO)

I need to write Java binding for GPIO library. Decided to go with JNI for the purpose. All of the references have examples with using standard C libraries with functions such as printf or, from scientific library with method such as multiply. The…
Meenohara
  • 314
  • 4
  • 9
1
2 3
12 13