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
2 answers

java wrapper for .c code

I have the following c code: test.c #include #include int add (int a, int b) { a=4; b=4; return a+b; } int add_pointer (int *a, int *b) { printf("values of a,b: %d,%d \n",*a,*b); return ((*a)+(*b)); } char*…
just ME
  • 1,817
  • 6
  • 32
  • 53
4
votes
1 answer

Cmake build in specific order

I'm trying to create a JNI jar with CMake. For that the following has to be done in the appropriate order: compile .class files generate .h headers build native library jar everything where is done with add_jar() (I prefered that at…
quimnuss
  • 1,503
  • 2
  • 17
  • 37
4
votes
1 answer

Image stitching in android using OpenCV

I am trying to stitch images like Panorama View in android.I am using Android NDK and OpenCv library for that.I am using below code of Jni for stitching images First Method: extern "C" { JNIEXPORT void JNICALL…
4
votes
1 answer

Exception in thread "main" java.lang.UnsatisfiedLinkError: RunnerClass.parsecmdline(ILjava/lang/String;)V

I have a test case where I am trying to access the C code from my Java program using JNI. Steps involved are as follows : 1. A Java program calling the native methods : public class RunnerClass{ public native void win32_svc_install(); …
Abhishek
  • 1,974
  • 5
  • 31
  • 67
4
votes
3 answers

SWIG pointers and Java arrays

The SWIG documentation explains how a variety of input types in C, like this: void spam1(Foo *x); // Pass by pointer void spam2(Foo &x); // Pass by reference void spam3(Foo x); // Pass by value void spam4(Foo x[]); // Array of…
Buggieboy
  • 4,636
  • 4
  • 55
  • 79
4
votes
1 answer

JNI String return value

I have a Java instance method which returns a String and I'm calling this method through JNI in C++. I have written the following code: const char *DiagLayerContainer_getDESC(JNIEnv *env, jobject diagLayer) { jclass diagLayerClass =…
Salvatore
  • 1,145
  • 3
  • 21
  • 42
4
votes
2 answers

Android SDK app failed to load library

Heyho. I've got the same error message as this guy: "Android NDK app failed to load library" and i'm trying to transfer these answers here on my situation for hours now, but it doesnt work. Can someone help me? It's this opensource project here,…
trek711
  • 207
  • 3
  • 11
4
votes
2 answers

android: permission denied while opening /dev/video4 (webcam) from JNI

I have configured v4l2 on my android device. I plug the webcam and see that /dev/video4 node is created. But when I try to open it from my JNI layer it says "Permission denied" I have tried the following 1) Change the permission of /dev/video4 so…
4
votes
1 answer

Is a One-Time Loss of Reference to Allotted Native Memory by an Android Application a Big Deal?

I believe explaining the context surrounding this problem will only muddle things up, so I will cut straight to the chase: If an Android application allots a small amount of native memory through JNI, and then looses the reference to that memory…
orb
  • 1,263
  • 1
  • 10
  • 16
4
votes
1 answer

Fill a string array in JNI layer

I am new to Java programming and have a basic question. I would like to pass a string array to JNI layer. Inside the JNI function can the array be filled with strings? All the posts either talk how to return a string array from JNI layer or how…
ravi raj
  • 57
  • 4
4
votes
2 answers

Native shared library loaded to slow in Android

I have a shared library placed in libs/armeabi folder. It is loaded using System.loadLibrary("library_name.so"); The size of the library is around 3MB. The loading time is very long. It sometimes last almost 20 seconds. It blocks my GUI. I tried to…
sinisha
  • 1,013
  • 13
  • 30
4
votes
1 answer

Invoking Java from C++: how to catch/detect a fatal JVM error?

I'm developing a C++ program (Win32, MS Visual Studio 2008) which creates a Java VM via JNI as outlined here. It has been working fine for a long time, with both Java 6 and Java 7. Today I have installed a new version of JRE; something went wrong in…
4
votes
4 answers

NewString() & NewStringUTF() showing error not valid Modified UTF-8:

I am trying to pass char* from C++ to java using JNI in android. I have tried number of ways to pass that data 1) Using NewStringUTF: const char* data = getData(); // this method returns a char array. env->NewStringUTF(data); Executing above code…
Sagar Ekbote
  • 295
  • 1
  • 3
  • 11
4
votes
1 answer

How to unload a dll which gets loaded by System.load(path to dll)

Is there any way to unload a DLL which gets loaded in the application using System.load() API call.
Kamal Joshi
  • 1,647
  • 4
  • 17
  • 12
4
votes
1 answer

Java cannot load shared object library with JNI on OSX

I'm trying to use JNI to join Java and C in the simplest way on my friend's 64-bit OSX and I'm getting this error. Here's everything involved: test.java public class test { static {System.loadLibrary ("test");} native void aaa (); …
TreeTree
  • 3,200
  • 3
  • 27
  • 39