call native function from java

Hello, I trying call c++ function from java. But, when i calling this function my applications crashes. Can you help me find error?

in LogCat

@
06-07 15:02:45.863: E/AndroidRuntime(17975): FATAL EXCEPTION: GLThread 7535
06-07 15:02:45.863: E/AndroidRuntime(17975): java.lang.ExceptionInInitializerError
06-07 15:02:45.863: E/AndroidRuntime(17975): at org.hk.etalon.MainActivity.RequestProduct(MainActivity.java:261)
06-07 15:02:45.863: E/AndroidRuntime(17975): at org.cocos2dx.lib.Cocos2dxRenderer.nativeTouchesEnd(Native Method)
06-07 15:02:45.863: E/AndroidRuntime(17975): at org.cocos2dx.lib.Cocos2dxRenderer.handleActionUp(Cocos2dxRenderer.java:130)
06-07 15:02:45.863: E/AndroidRuntime(17975): at org.cocos2dx.lib.Cocos2dxGLSurfaceView$9.run(Cocos2dxGLSurfaceView.java:257)
06-07 15:02:45.863: E/AndroidRuntime(17975): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1424)
06-07 15:02:45.863: E/AndroidRuntime(17975): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
06-07 15:02:45.863: E/AndroidRuntime(17975): Caused by: java.lang.UnsatisfiedLinkError: Couldn’t load nativecall: findLibrary returned null
06-07 15:02:45.863: E/AndroidRuntime(17975): at java.lang.Runtime.loadLibrary(Runtime.java:365)
06-07 15:02:45.863: E/AndroidRuntime(17975): at java.lang.System.loadLibrary(System.java:535)
06-07 15:02:45.863: E/AndroidRuntime(17975): at org.hk.etalon.JNIBridgeBack.(JNIBridgeBack.java:9)
06-07 15:02:45.863: E/AndroidRuntime(17975): … 6 more
@

org_hk_etalon_JNIBridgeBack.cpp

@
#include “org_hk_etalon_JNIBridgeBack.h”
#include
#include <jni.h>
#include “platform/android/jni/JniHelper.h”

using namespace cocos2d;

#ifdef cplusplus
extern “C” {
#endif
JNIEXPORT void JNICALL Java_org_hk_etalon_JNIBridgeBack_invokeNativeFunction
{
}
#ifdef
cplusplus
}
#endif
@

org_hk_etalon_JNIBridgeBack.h

@
/* DO NOT EDIT THIS FILE - it is machine generated /
#include <jni.h>
/
Header for class org_hk_etalon_JNIBridgeBack */

#ifndef Included_org_hk_etalon_JNIBridgeBack
#define
Included_org_hk_etalon_JNIBridgeBack
#ifdef cplusplus
extern “C” {
#endif
/*
* Class: org_hk_etalon_JNIBridgeBack
* Method: invokeNativeFunction
* Signature: V
*/
JNIEXPORT void JNICALL Java_org_hk_etalon_JNIBridgeBack_invokeNativeFunction
;
#ifdef
cplusplus
}
#endif
#endif

@

file JNIBridgeBack.java

@
class JNIBridgeBack{
static {
System.loadLibrary(“org_hk_etalon_JNIBridgeBack”);
}
public native void invokeNativeFunction();

}
@


org_hk_etalon_JNIBridgeBack.h.zip (0.4 KB)

Well, I think that you mean that you want to call java from c++. There is great info about it here : http://www.cocos2d-x.org/boards/6/topics/3769
Basically - you don’t have to make a library and load it. There are easier ways to do it, exlplained in the post mentioned above.

No, I want to call c++ from java.

Document [[How to use jni]]
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_use_jni#2-c-code-invoke-java-code

Zhe Wang wrote:

Document [[How to use jni]]
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_use_jni#2-c-code-invoke-java-code

I reed this topic, I can’t find error in my code, and i want " Java code invoke c++ code"

http://www.cocos2d-x.org/wiki/How_to_use_jni
The documentation seems deleted?

I want to invoke GL Thread functions from Java side. Is that possible? I always get SIGSEGV 11 when I call functions that related to GL Thread, like Node::addChild.

This is your problem:
Caused by: java.lang.UnsatisfiedLinkError: Couldn’t load nativecall: findLibrary returned null

This can mean several things, but the first thing to look is the exact name of the .so library.

System.loadLibrary(“org_hk_etalon_JNIBridgeBack”); will load “liborg_hk_etalon_JNIBridgeBack.so”

if your .so is just named libJNIBridgeBack.so then you should just use System.loadLibrary("JNIBridgeBack"); It all depends on your .so name, how to call it.