jni

How can I catch SIGSEGV (segmentation fault) and get a stack trace under JNI on Android?

I'm moving a project to the new Android Native Development Kit (i.e. JNI) and I'd like to catch SIGSEGV, should it occur (possibly also SIGILL, SIGABRT, SIGFPE) in order to present a nice crash reporting dialog, instead of (or before) what currently happens: the immediate unceremonious death of the process and possibly some attempt by th...

How to access arrays within an object with JNI?

JNI tutorials, for instance this one, cover quite well how to access primitive fields within an object, as well as how to access arrays that are provided as explicit function arguments (i.e. as subclasses of jarray). But how to access Java (primitive) arrays that are fields within an jobject? For instance, I'd like to operate on the byte...

JNI dependent libraries

Hi, I'm running a library via JNI (I didn't write it), and internally it calls another DLL. I get an error saying "Can't find dependent libraries" unless I put the path of the other DLL on the system PATH variable (I'm on Windows XP). I'd like to be able to handle this on the java command line, and I've already tried adding it to -Djava....

Is there a Java library of Unix functions?

I am looking for a Java library to interface with standard Unix functions, i.e. stat(), getpwuid(), readlink(). This used to exist, and was called javaunix. It was released back in 2000. See this announcement. But the project page is now gone. Is there any modern replacement for these types of functions in Java today? One could mak...

"Not enough storage is avaliable to process this command"

Hello; When my program runs, following error was taken: Excepiton in theard "AWT -EventQueue -1" java.lang.UnsatisfiedLinkError: program.dll: Not enough storage is avaliable to process this command [java] at java.lang.ClassLoader$NativeLibrary.load<Native Method> [java] at java.lang.ClassLoader.loadLibrary0<ClassLoader.java:1751> [jav...

What is the easiest way to call a Java method from C++?

I'm writing a C++ program which needs to be able to read a complex and esoteric file type. I already have a Java program for handling these files which includes functionality to convert them into simpler file formats. My idea is, whenever my program needs to read info from a complex file, to have it call the Java method to convert it t...

Prevent Java from loading library more than once

I have several classes that use the same JNI library, called "jni". In each of those classes, I have a System.loadLibrary() call in the class's static initializer: Class class1 { static{ System.loadLibrary("jni"); } ... } Class class2 { static{ System.loadLibrary("jni"); } ... } The only proble...

JNI: Long-object created with wrong value

Hi! I am writing a c-jni function in Android, and I am having problems with creating a Long-object. I have succeeded in calling the constructor, but when I read the value of the object with longValue, I get the wrong result. jmethodID longConstructor; jmethodID longGetLongValue; jclass cls; jobject obj; // Create a object of type Long...

Check if a dll library is already loaded? (Java)

Hey Folks, In a Java program i am writing i make a jni call to a dll and load the library on startup as follows static { System.loadLibrary("LdapAuthenticator2"); } I then implemented another class that loads the same library and am getting an error saying that the library is already loaded, is there any way to check if the librar...

How to diagnose Java JNI EXCEPTION_ACCESS_VIOLATION errors in Windows Vista

We have a Java application that uses some C++ libraries through JNI. The application used to work just fine in Windows XP, but it does not work in Windows Vista, it just crashes the JVM right away. We also wrote the C++ libraries and produced JNI bindings using SWIG. We are a little bit clueless on where to start looking for a way to f...

Invoking time-consuming JNI task as a thread

I'm having a tough problem with invoking a native function using JNI from a thread. The native function is legacy code that performs a computation-intensive task. Since I'd like not to freeze the rest of the program, the computation should be performed in a background thread. EventBus is used to send the calculation result back to the m...

Returning null from native methods using JNI

Hi, I have some native code which returns a jbyteArray (so byte[] on the Java side) and I want to return null. However, I run into problems if I simply return 0 in place of the jbyteArray. Some more information: The main logic is in Java, the native method is used to encode some data into a byte stream. don;t ask.. it has to be done li...

MATLAB + JNI = error?

Anyone out there used MATLAB's javaObject() function with a JAR file that uses JNI? I'm trying to get JHDF5 running and it seems like it bombs when it tries to get access using jhdf5.dll so I don't really know what to do next. :( edit: I am NOT trying to read basic HDF5 files. I have my own custom Java code that does something with HDF...

Is there a market for JNI?

JNI is a peculiar little corner of the universe. I was wondering if there is a market there for specialty contract work. From what I can tell: (1) JNI usage is rather rare these days. (2) Most devs are not as good at it as they might think. (3) Being rare, it is a labor to come up to speed (again) when called upon to do so. The poten...

java - JNI/JNA - Get Window Title

Looking to get back into the development space; primarily using Java to call some native win32 functions (I don't desire to build in .NET).... Can someone point me to a place where I can read the title from a differnt running window using Java (JNI/JNA/SWIG). Assume you would know where in the memory space the application you are attemp...

When are -framework and -I/System/.../Example.framework/Headers/ needed?

I am trying to compile a JNI library which uses carbon from the command line. If I don't -I/System/.../JavaVM.Framework/Headers/, It can't find any of the jni types, and gives errors. If I just -I/System/.../FlatCarbon.framework/Headers but don't "-framework Carbon", it compiles fine, but the linker gives an error about an undefined sy...

How to create a BMP file from raw byte[] in Java

I have a C++ application which communicates with a camera and fetches raw image-data. I then have a Byte[] in C++, which i want to send to Java with JNI. However, i need to convert the raw Byte[] to an real file format(.bmp was my first choice). I can easily do this if i write it from C++ to an file on the hard-drive, using BITMAPFILEI...

When to recompile JNI bindings and client code?

Let's say I hav: a C library libfoo, a package org.foo.jni of JNI bindings to libfoo, and a package com.user.of.foo of client code. Obviously, if functions that org.foo.jni touches in libfoo change, I need to recompile the classes in org.foo.jni. And, also obviously, if methods that com.user.of.foo touches in org.foo.jni change, I n...

How to call c++ functionality from java

I have a Java program that is mostly GUI and it shows data that is written to an xml file from a c++ command line tool. Now I want to add a button to the java program to refresh the data. This means that my program has to call the c++ functionality. Is the best way to just call the program from java through a system call? The c++ progr...

Returning char array from java to C - JNI

I have a object store in Java. My C program stores data (in form of char array) in java. Now I wish to retrieve data from my store. I cannot find any function call that returns me an char array. How can I do this? ...