in my src folder, in the package org.cocos2dx.lib in the class Cocos2dxActivity
...
private native int nativeAdd(int a, int b);
public void setLocalizacionLanguage() {
int sum = this.nativeAdd(1, 2);
}
...
And in my C*+ project, in a random class in the .cpp i have
<pre>
… #include “android\jni\JniHelper.h”
…
jint Java_org_cocos2dx_lib_Cocos2dxActivity_nativeAdd
{
return a* b;
}
…
I compile the c++ project without problems (i’m putting all JNI related code between \#if (CC\_TARGET\_PLATFORM == CC\_PLATFORM\_ANDROID) )
but when I compile and execute in java it crashes with :
W/dalvikvm(4264): No implementation found for native Lorg/cocos2dx/lib/Cocos2dxActivity;.nativeAdd (II)I
W/dalvikvm(4264): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
E/AndroidRuntime(4264): FATAL EXCEPTION: main
E/AndroidRuntime(4264): java.lang.UnsatisfiedLinkError: nativeAdd
E/AndroidRuntime(4264): at org.cocos2dx.lib.Cocos2dxActivity.nativeAdd(Native Method)
E/AndroidRuntime(4264): at org.cocos2dx.lib.Cocos2dxActivity.setLocalizacionLanguage(Cocos2dxActivity.java:143)
E/AndroidRuntime(4264): at com.games.fvz.twice.FVZ_2_1.onCreate(FVZ_2_1.java:34)
E/AndroidRuntime(4264): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(4264): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(4264): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(4264): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(4264): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(4264): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(4264): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(4264): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(4264): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(4264): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(4264): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
E/AndroidRuntime(4264): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/AndroidRuntime(4264): at dalvik.system.NativeStart.main(Native Method)
so, i’m completely lost. I do not understand if i should create a class for the functions, declare them in another place or what is happening.
If you could help i would be truly happy
OK, i know what i’m doing wrong, although i don’t completely understand how this works, i can’t just put the C*+ function in any class, it has to be “linked” to the java project. In my case, it’s “main.cpp” when i change my c*+ function in there, i can find it without problems.
i met the same problem do you solve it ?
chuel chuelin wrote:
OK, i know what i’m doing wrong, although i don’t completely understand how this works, i can’t just put the C*+ function in any class, it has to be “linked” to the java project. In my case, it’s “main.cpp” when i change my c*+ function in there, i can find it without problems.
>
thanks and sorry!