jni

Java generics and JNI

Hi, Is it possible to call a native CPP function using JNI which takes generic arguments? Something like the following: public static native <T, U, V> T foo(U u, V v); And then call it like: //class Foo, class Bar, class Baz are already defined; Foo f = foo(new Bar(), new Baz()); Can anyone please provide me with a sample which is...

OpenCV NDK Android help

I am assuming that using the OpenCV code here: http://github.com/billmccord/OpenCV-Android#readme is the best way to use OpenCV on Android, with the NDK. I am still stuck as to how i get from the C definitions of functions to the ones i declare in OpenCV.java in my Android project (example: cvFindContours( void* img, CvMemStorage...

Copying a byte buffer with JNI

I've found plenty of tutorials / questions on Stackoverflow that deal with copying char arrays from C/JNI side into something like a byte[] in Java, but not the other way around. I am using a native C library which expects a byte array. I simply want to get data from a byte[] in java, into preferably an unsigned char[] in C. Long stor...

Java Native Access doesn't do C++, right?!

I've found many references online (including some on stackoverflow) to JNA being used for C++ libraries, but nothing I can find in the JNA docs indicates that's possible. There doesn't seem to be any way to wrap a C++ class, in particular. I need native access to use RTAudio, but all of RTAudio's functions are member functions of the RT...

java.lang.UnsatisfiedLinkError: Method inside dll is not accessible

I am trying to access the function available inside the .dll file. But it give exception like "Exception in thread "main" java.lang.UnsatisfiedLinkError: *.jniGetAudioInputLevel()D". DLL file is loaded but when I try to access the methods it give an error message. According to my knowledge:- This exception only occurs if the .dll is ...

creating a JVM from within a JNI method

Is it possible to create a JVM from within a JNI method using the JNI API? I've tried to do this using the JNI function "JNI_CreateJavaVM()", but it's not working (the function keeps returning a value less than zero). Here is the basic code I'm using (C++): JNIEnv *env; JavaVM *jvm; jint res; #ifdef JNI_VERSION_1_2 JavaVMInitArgs vm_...

interpreting Java-native communication performance

Right now I'm using JNA for Java-native communication and am pleased with its simplicity. However I do need to optimize performance and am considering using other bindings. My question is this: what part of Java-native communication is the "expensive" part? Is it the passing of data between them? Let me put it another way. Right now t...

Tomcat crashes if make mutlithreaded native call using Jace JNI

I am using Netbeans to build a java web project (tomcat 6.02 based) which loads a c++ native dll. I am using Jace library which wraps JNI. In my java code I have a static callback function which I call from c++ code. I am trying to invoke this callback in a new thread using boost.Thread but tomcat just dies without any message or crash ...

java.lang.UnsatisfiedLinkError, mach-o but wrong architecture on Mac10.6.2

I was trying to run a project in my local machine. I tried to load this jnilib file which I got from a running instance of this project on my Mac 10.6.2, System.load(lib.getAbsolutePath()); then I got this exception thrown: java.lang.UnsatisfiedLinkError, mach-o but wrong architecture I have check the jnilib with file command: l...

How to debug a problem when loading native libs in Java ?

Hey guys, I have a problem relative to JNI and Java. Here is the thing : the client wants us to install a certain app on his system. This app uses native libs, but the client does not want to put these libs in his system folder, for reasons I don't really know or understand, but can't change. To circumvent thius problem, I tried to lau...

Java Type Mapping for Java Native Access

I have a C function defined as follows: int s3vold_(void) {...} To create a Java methods with the same argument type as the native function does the void parameter map to Pointer or nothing? E.g., int s3vold(Pointer p) {...} or int s3vold() {...} The JNA docs only refer to void* ...

JNI Application State

How is state kept when accessing methods through JNI? In the example below my Java code is calling the native method drawFromJni, will my native class _nc be persisted between calls? If there were better native debugging tools for the NDK this would be pretty easy to find out, but I'm really having problems with the NDK and C++. exter...

Programming language decision for C++ legacy project workflow

I have quite a lot of C++ legacy code modules from my colleagues, each doing different jobs. Unfortunately they are poorly written and yes, all GNU C++ code running under Linux. I want to write a controller program to make singular C++ module a workflow for a very urgent demo. Also I need to write a front-end web-app allowing clients s...

Facing an error "*** glibc detected *** free(): invalid next size (fast)"

Developer environment: CentOS 4.7, Kdevelop 3.1.1, gcc 3.4.6 I run a java test client that loads a C++ shared library using JNI. There are three components in my application, Java client C++ shared library which acts as a JNI wrapper. (I will call it "wrapperlibrary") C++ shared library containing business objects. (I will call it "b...

Java web application cannot use native library (.so)

Hi all, Technical summary: I'm developing a Java web service deployed on GlassFish v3, running on CentOS 5. My web service uses functionality provided by a native library (.so) . The native library works fine, however I am not having much luck in configuring the environment correctly to load the native library yet not be affected by we...

Getting text data from C++ using JNI through std::ostream into Java

Hi everyone, I have a class in C++ which takes an std::ostream as an argument in order to continuously output text (trace information). I need to get this text over to the Java side as efficiently as possible. What's the best way to do this? I was thinking of using a direct buffer, but another method would be to take all the function cal...

JNI: How can i check if jobject is a null object in native c code

JNI: How can i check if jobject is a null object in native c code ...

Static libraries and JNI

I have created a header file and a corresponding .c file full of functions I would like to use with a java program. I created a JNI header file using javah. I'm using gcc to compile my header file. How can I link my regular c object file with my JNI static library to get a static library that utilizes my C library? I'm using gcc to c...

Copying C Array into Java Array Using JNI

I have an array of unsigned integers in C and a java array of longs. I want to copy the contents of the unsigned integers to the java array. So far, the only function that I've found to do this is SetLongArrayRegion(), but this takes an entire buffer array. Is there a function to set only the individual elements of the java array? Th...

Java JNI: global variable collision in native code

Good day, masters. Suppose I have a java class A: class A { public A() {} public native void setValue(String value); public native String getValue(); } When implementing the native C code, a global char[] variable is used to store the value just be set by native setValue method. The getValue method just return that global ...