Questions tagged [java-native-interface]

The Java Native Interface (JNI) gives both the ability for JVM implementations to run system native code and the ability for native code to run Java code (by creating new JVM instances). The most common target languages for JNI are C and C++, for which at least the Sun/Oracle JDK implementations provide helper commands (javap - for code disassembly, javah for c code generation).

The JNI defines a standard naming and invocation convention which allows the Java virtual machine to locate and invoke native methods.

In fact, JNI is built into the Java virtual machine, allowing the Java virtual machine to invoke local system calls which perform input and output, graphics, networking, and threading operations on the host operating system.

The naming and invocation convention has been standardized by the JNI specification.

References:

9715 questions
4
votes
1 answer

Is there a way to check if jobject is a local or global reference?

I cannot find an answer if there is a way to test an arbitrary jobject in order to detect if it is a local or global reference. I do not see it in JNI documentation. The reason for this question is to add some error checking and logic for my custom…
minsk
  • 755
  • 1
  • 8
  • 16
4
votes
3 answers

unresolved external symbol __imp__JNI_CreateJavaVM@12 referenced

I want to write a C++ program which calls Java method. I am trying to invoke a Java function from C++. As described here http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/invocation.html but I get this error while debugging and can not…
Horasan Lee
  • 89
  • 1
  • 8
4
votes
1 answer

JNI memory leak from byte array

I have a java program that calls a native function many times over. My problem is that this function has a memory leak and everything that I do to get rid of it cause a memory dump. Any help would be greatly appreciated. This is my code JNIEXPORT…
Tyler Davis
  • 2,420
  • 2
  • 23
  • 19
4
votes
3 answers

How do I define the JNI method signature of a generic class?

I have a base class defined in java. I would like to call a native method like so: public class Base { public void doSomething() { nativeDoSomething(); } private native void nativeDoSomething(); } My question is, how do…
MM.
  • 4,224
  • 5
  • 37
  • 74
4
votes
6 answers

Accessing RPG on iSeries from Java

Has anyone had good experiences of talking direct to RPG programs running on a V5R4 iSeries machine from Java? If so, what are the recommendations of the community, and what pitfalls should I try to avoid? From the various pieces of literature and…
lawsonj2019
  • 163
  • 2
  • 6
4
votes
2 answers

How to store a C variable (JNI) to a Java class instance

Background My application has now reached a bottleneck where the slowest part of it is the AES encrypt and decrypt streams through which all data must pass. In order to overcome this I plan to implement this ciphering in native code via JNI and…
md_5
  • 630
  • 9
  • 26
4
votes
3 answers

How to get the value of an enum being passed to the JNI

I have a Java application and JNI (dll). I want to know how to get the value of the enum (int) that is being passed as a parameter to the JNI. Here's the enum (Java): public enum envelopeType { NOT_SPECIFIED(-1), NONE(0), IMAGE(1), …
BebzSusuma
  • 71
  • 1
  • 3
  • 7
4
votes
1 answer

Create bitmap from byte array, which is decompressed from a JPEG file via libjpeg

I used libjpeg (C library) to decompress a JPEG file. Now I have an unsigned char array. How can I create a bitmap from that array in JNI ?
Co-Gia
  • 103
  • 2
  • 10
4
votes
1 answer

How to make JNI calls from a Service even if application is closed?

I have an app that makes very heavy image processing. My app process very low resolution of the image in the activity and i am intenting to make full resolution image processing in a Service so even if app is closed by user the processing and saving…
4
votes
3 answers

Android Expand JNI Local Reference Table

I have a lot of objects to create on c++ and send it to java, I'm using the env->DeleteLocalRef(obj); but I'm getting the following error: 06-10 18:43:56.976: E/dalvikvm(11536): JNI ERROR (app bug): local reference table overflow (max=512) 06-10…
ademar111190
  • 14,215
  • 14
  • 85
  • 114
4
votes
1 answer

Passing USB file descriptor to Android NDK program

I am trying to port some software written in C to the Android platform. This software has a component that reads and writes from and to a connected USB device. What I am trying to do is open up a connection to the device in Java, then pass the…
user142162
4
votes
0 answers

Android Webview using Leaflet - JNI Error

I'm developing an Android application containing a Webview. The HTML corresponding to the webview contains mainly JavaScript code ; it retrieves a map of a building from a Geoserver. I use Leaflet to display the different layers. Each base layer is…
4
votes
1 answer

Calling C++(cocos2dx) method from java(android) for my in-app billing

I'm trying to add in-app billing in my cocos2dx-android project. I am able to give a call to java function from c++ class via jni. This is the way i give a call to my java function via jni. JniMethodInfo t; …
4
votes
1 answer

Invoking Java Jar code from JNI in C++

I'm trying to emulate this (http://snuggletex.sourceforge.net/maven/xref/uk/ac/ed/ph/snuggletex/samples/MinimalExample.html) code inside my C++ language, in order to obtain natively some LaTeX to MathML conversion of mathematical formulæ, but after…
jackb
  • 695
  • 8
  • 26
4
votes
2 answers

UnsatisfiedLinkError when using a JNI native library from Grails application

I have an application where I need to use a Native Library: libfoo.so My code is as follows: Accessor.java: public class Accessor { static { String path = "/usr/lib/libfoo.so"; System.load(path); } ... } This…