jnienv


JNI_CreateJavaVM() terminates with exit code 1

亡梦爱人 提交于 2019-12-29 08:38:05
问题 I'm trying to call a Java method from C++ using JNI. To do that I've installed jdk1.7.0_51 , linking against jdk1.7.0_51\lib\jvm.lib , including jdk1.7.0_51\include and jdk1.7.0_51\include\win32 . using the following code in Visual Studio 2012 I tried to create a Java vm object - but the function always terminates my application with exit code 1 (the function doesn't return 1: my program terminates completly and sends the exit code 1). #include <iostream> #include "jni.h" int main(int argc,

Keeping a global reference to the JNIEnv environment

那年仲夏 提交于 2019-12-28 02:31:07
问题 I am storing off JNIEnv in a global so I can call static java methods later. But is it nessasary to store off a global pointer to the JNIEnv , they way one would with any other java object, or is it a special case that does not require this. JNIEnv* globalEnvPointer; [JNICALL etc] void init(JNIENv* env, [etc]) { //required? globalEnvPointer = (JNIENv*) (env*)->GetGlobalRef(env, env); //or is this OK? globalEnvPointer = env; } Edit I'm bing a bit dumb here, all the methods that will use

call java methods with argumenrs in JNI

天大地大妈咪最大 提交于 2019-12-25 02:52:24
问题 I am working on JNI program and I am not able to call a java method from my C++ program. The code snippet of java method is here public static void getTables(Connection conn) throws Exception { String TABLE_NAME = "TABLE_NAME"; String TABLE_SCHEMA = "TABLE_SCHEM"; String[] TABLE_TYPES = {"TABLE"}; DatabaseMetaData dbmd = conn.getMetaData(); ResultSet tables = dbmd.getTables(null, null, null, TABLE_TYPES); while (tables.next()) { System.out.println(tables.getString(TABLE_NAME)); System.out

call java methods with argumenrs in JNI

北慕城南 提交于 2019-12-25 02:52:13
问题 I am working on JNI program and I am not able to call a java method from my C++ program. The code snippet of java method is here public static void getTables(Connection conn) throws Exception { String TABLE_NAME = "TABLE_NAME"; String TABLE_SCHEMA = "TABLE_SCHEM"; String[] TABLE_TYPES = {"TABLE"}; DatabaseMetaData dbmd = conn.getMetaData(); ResultSet tables = dbmd.getTables(null, null, null, TABLE_TYPES); while (tables.next()) { System.out.println(tables.getString(TABLE_NAME)); System.out

Qt JNI : Invalid indirect reference 0x61382e48 in decodeIndirectRef

做~自己de王妃 提交于 2019-12-24 03:05:08
问题 I am trying the Qt project that captures audio data from mic on android. I refereed this article : Android AudioRecord example, and wrote it to Qt code. int recorderSampleRate = 44100; int recorderChannels = QAndroidJniObject::getStaticField<jint>("android/media/AudioFormat", "CHANNEL_IN_MONO"); int recorderAudioEncoding = QAndroidJniObject::getStaticField<jint>("android/media/AudioFormat", "ENCODING_PCM_16BIT"); int sourceType = QAndroidJniObject::getStaticField<jint>("android/media

Android Jni : crash in global and local ref variables

大城市里の小女人 提交于 2019-12-22 14:47:26
问题 I have jni c++ code that calls java objects methods, example : jclass JIOManager = CJavaEnv::getInstance()->env()->FindClass(ioManagerName); ..... some code CJavaEnv::getInstance()->env()->DeleteLocalRef(JIOManager); this works really fine when executes in main thread, but when I try to execute this in another thread it crash because it says that it is created in another thread :O !! but after I read in google android developer website, they say accessing Global Ref from any thread is fine,

What is the best way to save JNIEnv*

柔情痞子 提交于 2019-12-17 04:36:08
问题 I have an Android project with JNI. In the CPP file which implements a listener class, there is a callback x() . When x() function is called, I want to call another function in a java class. However, in order to invoke that java function, I need to access JNIEnv*. I know that in the same cpp file of the callback, there is a function: static jboolean init (JNIEnv* env, jobject obj) {...} Should I save in the cpp file JNIEnv* as member variable when init(..) is called? and use it later when the

Getting Started with JNI and C under Windows

旧巷老猫 提交于 2019-12-14 04:25:20
问题 I'm new in Java learning and first time want to get start JNI. And I am working with Cygwin and I have created a file with .java (Helloworld.java) extension as follows: class HelloWorld { private native void print(); public static void main(String[] args) { new HelloWorld().print(); } static { System.loadLibrary("HelloWorld"); } } Then I compile the file through the command line ( javac Helloworld.java ) after that create a native header file through command javah –jni Helloworld Then also

When creating New<PrimitiveType>Array from C++ code in JNI how to release the <PrimitiveType>Array's buffer?

拟墨画扇 提交于 2019-12-11 18:44:32
问题 I am currently writing a small emulator in C++ using Java as a GUI. In order to achieve this I am making JNI calls from my C++ code passing arrays of data to the GUI application. However due to the shear amount of calls I made in a test run, it has become clear that in my function to pass data a memory leak is occurring. Before my program has run: After my program has run and crashed due to lack of memory: (Please ignore the CPU usage this program currently uses, I am aware that repeated

JNI Linux segmentation fault

倾然丶 夕夏残阳落幕 提交于 2019-12-11 16:19:32
问题 My JNI library works flawlessly on Windows, however, on Linux I always get a strange segmentation fault. siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000000 The stack crace from the crash file is this: C [libfmodjavaL.so+0xfb8c] JNIEnv_::GetStaticObjectField(_jclass*, _jfieldID*)+0x18 C [libfmodjavaL.so+0xf72b] Logger::sendToSystemOut(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)+0x75 C [libfmodjavaL.so+0xf7c2] Logger

工具导航Map