Click here to Skip to main content
15,894,291 members
Everything / JNI

JNI

JNI

Great Reads

by Android on Intel
This blog outlines the steps needed to integrate Intel’s AES-NI instructions into an Android app via the OpenSSL library.
by Android on Intel
This document is focused on creating OpenCV-enabled applications for Android. If the target operating system of your application is Windows
by Android on Intel
In this paper, we introduce some of the new features in ART, benchmark it against the previous Android Dalvik* runtime, and share five tips for developers that can further improve application performance.
by Android on Intel
This article walks through an example Android application that offloads image processing using OpenCL™ and RenderScript programming languages.

Latest Articles

by Yochai Timmer
A way to avoid JNI's reflection oriented programming. Wrapping Java with C++
by mohamadArdestani
get shutdown message in java application with jni
by YevheniyK
The article describes a general approach to using Cocos2d-x on top of native components and relevant coding specifics for Cocos2d-x, iOS and Android.
by Luca Basso Ricci
How to build the JNI signature for a Java method

All Articles

Sort by Updated

JNI 

27 Mar 2024 by Yochai Timmer
A way to avoid JNI's reflection oriented programming. Wrapping Java with C++
14 Jul 2021 by getrelax
I want to connect and access to HSQL DB from C#. I am trying to use JNI to invoke Java code in C# environment. The challenge is how to write java import statement in C# environment. What I have tried: I used the reference shown in this link...
24 Jun 2021 by 15160877
I am trying to pass a string value from java to c. And, a hashmap from C to java. I am trying to pass this using same method in C. But, I can't do that in a same method. I need the string data to fill my hashmap. So, I need to do it inside a...
24 Jun 2021 by Richard MacCutchan
I have checked the JNI Documentation[^] and cannot see any support for HashMaps. You will need to use one of the supported types.
18 May 2021 by another_newbie
By looking at the definition of jbyte in jni.h I have: typedef int8_t jbyte; /* signed 8 bits */ So is it is always safe to convert jbyte to a signed integer without casting? What I have tried: So far I have tried int8_t
16 May 2021 by 15160877
I am trying to pass a LPWSTR to java via JNI. But, it only passes the first character of the string. Can someone suggest what to do? I'm passing the string like the following: jstring k = (*env)->NewStringUTF(env, lpstr); ...
16 May 2021 by KarstenK
Working with strings isnt so easy at all because every string has "under the hood" some encoding logic. This mean HOW the buffer of bytes is interpreted to the human readable string. Try also Memory view to see the details byte by byte. For this...
16 May 2021 by Rick York
It's acting like the JNI is expecting single-wide characters for that function because in a wide string the second byte of the pair will be zero for characters less than 256 so the function is seeing a string of a single character. Your options...
14 May 2021 by Richard MacCutchan
As I have tried to explain to you on many occasions, you cannot access Java objects form C except by using the types and code defined in the JNI documentation. A C++ map type is completely different from a Java Map type. I also suggested that you...
14 May 2021 by OriginalGriff
Repost: deleted. How many times are you going to post the same thing until you start listening and actually learning?
14 May 2021 by Member 15076657
I have been trying data from C file to java using JNI. But, when I try to pass it, the following error occurs in eclipse. # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at...
14 May 2021 by Rick York
The cause is in the message : writing address 0x0000018c That is obviously an invalid address for a pointer. There is another clue : Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) j Main.service(Ljava/util/HashMap;)V+0 j ...
13 May 2021 by Member 15076657
I have passed a hashmap from java to C. Now, I need to fill the hashmap and pass it back to java. This is my java code. Main.java import java.util.*; public class Main { static { System.loadLibrary("Tests"); } public void doProcess()...
13 May 2021 by Richard MacCutchan
You cannot use native methods to access a Java object in JNI. You can only use the Java types as defined in jni.h. So you have to figure out in your C code what the structure is and update it from that information. But it would be much simpler to...
12 May 2021 by 15160877
I want to send an empty hashmap from java to C. After that, I need to store data from C to hashmap and again pass it to java. I can now access my java functions from C. But, now I want to pass a hashmap from java and store the data and pass the...
12 May 2021 by Richard MacCutchan
You have to start again from the other side. You need to create a C library with a method that can accept a plain array from Java. The C code can then fill it with the data requested before returning to Java. The JNI documentation shows how to do it.
10 May 2021 by Member 15076657
I'm trying to run an .exe. When it runs, it shows the following error. Error occurred during initialization of VM Unable to load native library: Can't find dependent libraries What does this mean? JNIEnv* create_vm(JavaVM** jvm) { //JavaVM*...
10 May 2021 by Richard MacCutchan
OK, I have a working version, which required a couple of minor changes: #include JNIEnv* create_vm(JavaVM** jvm) { //JavaVM* jvm; /* denotes a Java VM */ JNIEnv* env; /* pointer to native method interface */ JavaVMInitArgs...
9 May 2021 by OriginalGriff
If you don't understand an error message, Google it: Error occurred during initialization of VM Unable to load native library: Can't find dependent libraries - Google Search[^] What it means is that a DLL is missing, or incompatible with the...
9 May 2021 by Member 15076657
I am using this as a reference to call my java class inside C program. But , JVM is not launching. Here is my code for launching jvm.
9 May 2021 by Richard MacCutchan
I do not know where you found that code but the official documentation is different: The Invocation API[^]. Also why do you write: mbstowcs(t, "C:\\Program Files (x86)\\Java\\jdk-16.0.1\\jre\\bin\\server\\jvm.dll", 400); jvm_dll =...
6 May 2021 by Member 15076657
I want to access my c code from java and get data from C struct using JNI. I want to achieve this using hashtable or hashmap. Here is my C struct: struct process { char str[]; char strr[]; int i; }; struct process *ptr; Now, I want to pass the...
6 May 2021 by Richard MacCutchan
Quote: Can I pass the data using Hashtable or Hashmap? Or can I pass the struct array directly to java? Is there any decent way for doing this? Sadly, no. The Java Native Interface is designed to allow C programmers to write support libraries...
6 May 2021 by KarstenK
Be happy that it works and move on. Transfering complex objects between different runtimes isnt possible because of memory layout. You may transfer some byte array in which the data is an reinterpret it. Like struct Data { int i; int lenstr; ...
6 May 2021 by OriginalGriff
Repost: deleted. This is the same question you asked an hour ago: Access a C structure array from java using JNI[^]
6 May 2021 by Richard MacCutchan
This is effectively the same question as Access a C structure array from java using JNI[^]. Please do not repost.
9 Aug 2019 by Srikanth Chadalavada
I am having an issue with windows closeHandle((Handle)port) function in our .dll. it is not returning. The issue happens every few hours. The java application using the .dll connects, reads and writes data. The last method call java application does is to write the data and release method is...
9 Aug 2019 by KarstenK
If you write on the port you should check that the data is written and than close the port. It is best to open only when needed and than close again. Read about the specific timeouts of that port. Be precise about not opened multiple ports or double close ports, this can lead to strange...
15 Sep 2018 by mohamadArdestani
get shutdown message in java application with jni
12 Jun 2018 by KarstenK
Normally JNI works and you have missed some details. Read the article Calling Java from C++ with JNI in which the JNI is used as I had been working with it. Check that the packages, classes and functions are public. At last you can try to do your work in Java and only export the results as...
12 Jun 2018 by Manish Sharma
I need to call some Java methods using C/C++ and then I need to use DPI in UVM or system verilog to call C methods. I dont have access for JAVA files or JAVA classes. I have a .jar file in which my class is present of which methods I need to access. I am using path of that .jar file in ...
9 Apr 2018 by ShrinidhiN
I need to reference a .Net COM dll in java. I have used jni4net libraries for the same. I have followed the steps mentioned in the video below : https://www.youtube.com/watch?time_continue=351&v=8OoSK_RWUe4 I have followed all the steps required to reference jni4net libraries but i get the...
23 Apr 2017 by amir tarek
i make a simple c function in Visual studio 6 this is the code #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved) { return TRUE; } extern "C" __declspec(dllexport) char __stdcall GetCompanyCode() { return 1; } i need to call the...
23 Apr 2017 by KarstenK
You must carefully read and understand the error message. Here is "Error looking up function 'GetCompanyCode': The specified procedure could not be found." So the linker says that dll is found but the function not. Check with the good olddepedency walker that the function name is properly...
12 Apr 2017 by vishalgpt
Hi to all, Is this possible to access c++ library functions in android without writing Jni Wrapper. Because i have to use a big library and writing jni wrapper for all the modules is a difficult task. Becoz the c++ modules consists of numerous structures and class. Please guide. What I have...
12 Apr 2017 by Nick_3141592654
It's not possible to use C++ without JNI - the point is that JNI *IS* native code, i.e. the very fact that you want to use C++ (or C) means that you are using a native library, within a Java environment => JNI. Remember that you only need to provide the JNI wrapper code for your API between the...
1 Nov 2016 by Member 12373848
I am developing a JavaFX application & a C++ dll whose method i want to call from JavaFX (java code). So, i have placed the dll in project directory, getting the working directory during runtime , hence creating the path to dll , setting the same path value to "java.library.path" & then loading...
31 Oct 2016 by KarstenK
The called function isnt properly exported with JNI from your C dll, maybe it is only the wrong data type as parameters. The first is ALWAYS the JNI pointer. Here is a fine looking tutorial where all is explained.JNI works that way, so take care to implement the c-dll in this manner.
26 Oct 2016 by Richard MacCutchan
See jni mfc - Google Search[^].Also, you already posted this question at How to monitor progress of burn using IMAPI 2.0 and pass updates to java[^]. Please do not repost.
26 Oct 2016 by KarstenK
The easiest way is to setup a timer in java and poll for the actual status in C++. It makes a lot sense to poll "only once" in a second.
26 Oct 2016 by KarstenK
You must correct initialize the MFC runtime before the first use, like it is here described.For updating the UI you must implement an interface function with JNI to the MFC-dll, in which the update (as message parameter) the signaled. Because the JRE/JNI and the MFC are in different...
26 Oct 2016 by Member 12373848
How to call a MFC dll from Java. So that it feels as if Java launched the MFC UI.I am developing a MFC dll using IMAPI 2.0 with C++ to burn data on DVD/CD. I want to call this dll from Java & hence the run MFC dll with its UI. This will help in monitoring the burn process.What I have...
26 Oct 2016 by Member 12373848
I am creating a dll using IMAPI 2.0 with C++, can anyone help in how to monitor progress of burn & conitinuously send updates from dll to Java.What I have tried:I was trying to attach IDiscFormat2Data Event to burn thread. But how send this update continuosly to Java.
5 Oct 2016 by YevheniyK
The article describes a general approach to using Cocos2d-x on top of native components and relevant coding specifics for Cocos2d-x, iOS and Android.
19 Sep 2016 by Tejas Sawant 13
Question is very simple I need alternate code for below line IntPtr i =Marshal.StringToHGlobalAnsi("Hello World");I am struggling a lot for same please help me.What I have tried:From 2 days trying every possible solution. But no output.
19 Sep 2016 by Richard MacCutchan
No you have not tried every possible solution, because I told you yesterday in http://www.codeproject.com/Questions/1130172/Csharp-code-to-JAVA-code[^] what you need to do. So now you need to go back and do it. The only way to interface between Java and a C/C++ dll is by using the JNI. And you...
18 Sep 2016 by Member 12373848
I am trying to write DVD RW / CD using IMAPI 2.0 with C++. The created dll is being called from a Java Application.I am getting a crash in code which is the following :## A fatal error has been detected by the Java Runtime Environment:## EXCEPTION_ACCESS_VIOLATION (0xc0000005) at...
18 Sep 2016 by Patrice T
Even with best will, it is not possible to help you with this.You should read thisAsking questions is a skill[^]
15 Sep 2016 by Luca Basso Ricci
How to build the JNI signature for a Java method
16 Feb 2016 by Simon Agholor
How to invoke Java methods from a .NET application.
11 Nov 2015 by W Balboos, GHB
The reason for the 'sometimes'   is that a pointer, du to the un-initialized pointer (null pointer) is likely being over-written with varying data.   It's value typically changes with each execution of your application.   Depending upon where it's pointing will depend upon if, or more likely,...
10 Nov 2015 by mayooran99
I have the a JNA structure which is throwing InvalidMemoryAccessException occasionally. Without changing the code,when I run it, it runs at times. At times it throw the exception as shown below.Exception in thread "main" java.lang.Error: Invalid memory accessat...
1 Oct 2015 by Android on Intel
This article walks through an example Android application that offloads image processing using OpenCL™ and RenderScript programming languages.
28 Aug 2015 by CPallini
See this Stack Overflow question: "Returning Mat object from native code to java in OpenCV"[^].
28 Aug 2015 by RupeshMote
I want to access c++ code from java program. For that I used concept of JNI.I declare one native method in java, whose return type is Mat class of opencv, as follows :public native Mat getFrames();Then using javah utility, I created c implementation(Header File) of my java class...
20 Jul 2015 by Android on Intel
In this paper, we introduce some of the new features in ART, benchmark it against the previous Android Dalvik* runtime, and share five tips for developers that can further improve application performance.
6 Jul 2015 by Android on Intel
This document is focused on creating OpenCV-enabled applications for Android. If the target operating system of your application is Windows
21 Jun 2015 by saudi-knight
So this is the error I get on Eclipse:## A fatal error has been detected by the Java Runtime Environment:## Internal Error (0xe0434352), pid=7696, tid=8632## JRE version: Java(TM) SE Runtime Environment (8.0_45-b15) (build 1.8.0_45-b15)# Java VM: Java HotSpot(TM) Client VM...
19 May 2015 by cth027
A tutorial to master the Java Native Interface with C++
22 Mar 2015 by Richard MacCutchan
It is not really clear what the issue is, but I suggest you take a look at https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html[^], which explains how to pass different types between Java and C/C++.
22 Mar 2015 by rahul15001
I have a string array like {"myname","yourname","hisname"} and I am trying to send this array to C with using JNI. I could not find any clear solution for this. I have tried to take this string as a chararray but no success.Is there a way to do this?
21 Mar 2015 by KarstenK
To be honest: The simplest and savest way is to use one dimension arrays with native data types and AVOID structs. Java and C have different memory layouts. Microsoft has solved this mess on its .net-languages.I would extend the interfaces of rhe func with size information:JNIEXPORT...
21 Mar 2015 by rahul15001
I have a int array likeint[][] coordinates = {{346, 640, 499, 666},{555, 640, 675, 666}};and I am trying to send this array to C with using JNI. I could find clear solution for one dimensional array but not for multidimensional array.public class PopulateCoordinates{public native...
20 Mar 2015 by KarstenK
I found this fine Java Programming Tutorial for JNI with example for int array.Very important is to release all memory carefully or the jni gets into trouble without any clear errors.
19 Mar 2015 by rahul15001
I have a int array like int[][] arrays = { array1, array2, array3, array4, array5 };where array1=30,40,20,40 ,array2=40,20,30,30 and I am trying to send this array to C with using JNI. I could not find any clear solution for this. I have tried to take this int as a intarray but no success.Is...
12 Feb 2015 by Android on Intel
This blog outlines the steps needed to integrate Intel’s AES-NI instructions into an Android app via the OpenSSL library.
7 Feb 2015 by guest000007
Install the latest MinGW with msysPut this new user variable in System properties -> Advanced -> Environment Variables:PATHC:\MinGW\binOpen msys.bat$ cd "path" // point to your folder where is the NIST makefile$ makeand hopla, the assess.exe is ready for use.
21 Jan 2015 by Richard Chambers
Exploring how to embed a Java VM into a C application and developing a native library for a Java application using JNI.
4 Sep 2014 by mohit_ranjan143
please provide the full code fro this android phonegap plugin's java script calli required urgently
16 Jul 2014 by Member 10378849
I search for solution 3 day still I cant find.My java file work normally and no error. I copied my java file "I2CInterface.java" to "jdk/bin" directory. Then "javac I2CInterface.java" the I2CInterface.class created succesfully. But "javah -jni I2CInterface" give error class couldnt found....
3 Jun 2014 by E.F. Nijboer
Git is a distributed version control system and github is an online location for sharing repositories. You cannot debug it directly. You need to download it or use:git clone --bare https://github.com/FreeRDP/FreeRDP.gitOf course you must have git installed. Download link:...
3 Jun 2014 by RaiBnod
I have imported the git project in my workstation, and now i want to debug the https://github.com/FreeRDP/FreeRDP/tree/master/client/Android/FreeRDPCore path project. Means want to debug the FreeRDPCore project to work with that project.Have you any idea under debugging it, please your help...
13 Dec 2013 by manish yadav
I am using http://www.sqlite.org/c3ref/open.html as a reference for using the sqlite c for opening the dbi m calling like this package com.example.offline; public class NativeLib { static { System.loadLibrary("sqlite3"); } ...
22 Oct 2013 by Member 10286395
he code below gives me all elements of any window but i want to know the particular button/link/textbox accessed by user ...User32.INSTANCE.EnumChildWindows(GetForegroundWindow(), new User32.WNDENUMPROC() { int count = 1; ...
21 Aug 2013 by KarstenK
Consider using a notification model. The callee changes the value and the called is performing some actions. like notifying other modules.That event driven model has a good performance and stability.
21 Aug 2013 by pasztorpisti
What is "loading same DLL simultaneously"? First: If you start a VC++ program that loads a DLL and you start a Java program that loads the same DLL then you have created two processes that have nothing to do with each other so your assumption that you require some kind of IPC to communicate...
20 Aug 2013 by KarstenK
The JNI interface works fine if you handle it very carefully.Everything should be transfered by value and then work on a local copy. Do dont work with pointer from C++ in Java and vice versa or some strange exceptions will hurt you :mad:That looks interesting for you:Sample JNI...
20 Aug 2013 by Buddhi Chaturanga
I constructed a java program using netbeans IDE that has ability to connect with a respective DLL; I want to connect and interchange data between my java program(.jar) and VSC++ program(.exe) through DLLs.JNI uses single Dll to invoke C/C++ function in native manner,In order to increase the...
23 May 2013 by PraveenOjha
An android game using NDK JNI and Java.
16 Mar 2013 by Ahsetau
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(); static{ System.loadLibrary("testDll"); ...
19 Feb 2013 by Leo Chapiro
You have to link with JVM's library (add some reference to libjvm.a to the tcc's command line).If you don't have a precompiled jvm.lib file for TurboC++, there is another option - link with the jvm.dll file and export all the methods from JVM manually. This uses the...
19 Feb 2013 by Moorthy Rajendran
JNI_CreateJavaVM(&jvm, (void **)&env, &args);tcc C:\TurboC++\Disk\TurboC3\BIN\CTest.c -I "C:\Program Files\Java\jdk1.6.0_16\include" -I "C:\Program Files\Java\jdk1.6.0_16\include\win32" -I "C:\Program Files\Java\jdk1.6.0_16\lib" -shared -o CTest.dllError: tcc: undefined symbol...
11 Feb 2013 by Member 8661141
I have to return a array of structure values from c++ (jni) to java. I have the c++ struture as followsMyCStructure{byte *Data;int dataLength;int width;int height;}mycstr;And i have my java structure aspublic class MyJavaStructure{ public byte[] Data; public...
3 Dec 2012 by Manish_Mohan
Hi all,Does anyone know how to resolve this exception.## A fatal error has been detected by the Java Runtime Environment:## EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d7a83f0, pid=6320, tid=6328## JRE version: 7.0_05-b05# Java VM: Java HotSpot(TM) Client VM (23.1-b03...
24 Sep 2012 by pasztorpisti
What about checking out and modifying existing code? How to Call Java Functions from C Using JNI[^]
24 Sep 2012 by sandeep vihaari
Hey hi. This is sandeep.I am also trying to do the similar kind of work you are doing, like calling a java method inside c. I have lot of errors. Can you please correct me where i am wrong.Errors mainly in the lines (CALLBACK *fpCJV)(JavaVM**, void**, JavaVMInitArgs*); HINSTANCE...
11 Sep 2012 by AhmdAxf
Hi All,I am working on a project similar to embedding opengl inside java in which a an animated figure is drawn into an AWT canvas using JNI and AWT native interface. I have a third party application software whose method for live video is providing the same functionality. I have played...
11 Sep 2012 by AhmdAxf
for the System.loadLibrary() call the dll file should be in path of java i.e system32 but i would recommend System.load() instead by which you would be able to give full path of the dll file and use it in any other java app usin that jar
20 Aug 2012 by Christian Graus
You're a developer, why not write a program to download the files, or even better, use an FTP program. How is this a programming question ?
20 Aug 2012 by Tarun22
i was trying to run dumpsys.cpp in android ndk using JNI interface i got the source code of dumsys from the following link "http://source-android.frandroid.com/frameworks/base/cmds/dumpsys/dumpsys.cpp"when i run the code i am getting following errors:-error: utils/Log.h: No such file or...
8 Aug 2012 by subrata kumar Nayak
since u want to create a A.dll and call B.dll from A.dll, so i would recommend u to jst create the B.lib and put it inside A.dll then u will be able to call the functions of both class A&B hope this will work........All the best.......
6 Aug 2012 by Sergey Vystoropskiy
Also I hade found this one http://code.google.com/p/android-cpp-sdk/[^]
6 Aug 2012 by Sergey Alexandrovich Kryukov
Did you try this one:http://www.teamdev.com/jniwrapper/[^],http://www.teamdev.com/jniwrapper/documentation/[^]?By documentation, it looks good, but unfortunately, it's commercial. And I never tried it.—SA
6 Aug 2012 by Volynsky Alex
Hi Sergey,You can see the SWIG (Simplified Wrapper and Interface Generator):http://www.swig.org/tutorial.html[^]http://www.swig.org/Doc2.0/SWIGDocumentation.html[^]I hope this will help you
6 Aug 2012 by Sergey Vystoropskiy
I want to start a small project on C++ for android. I don't like that ugly c-style JNI. Is there some good C++ wrappers ?
2 Aug 2012 by subrata kumar Nayak
i am creating an application in android using ndk and jni.In my app i have requirement to parse xml data.for which i have used libxml2.when i am making a static library of libxml2 and use,it works fine.But when i am trying to make a shared library and use it in my application i am...
2 Aug 2012 by subrata kumar Nayak
i have created an android application,here most of my code is in c so i have created it using jni. i have to create socket.so file, in which i have to use the libtest.so.while using the libtest.so in socket.so i get the error:undefined reference to function(). my function() is present inside...
23 Jul 2012 by subrata kumar Nayak
it was a silly thing...replace ' with \\' ,not with\'....thn rest are same as it was...