简体   繁体   中英

JNI and Android… UnsatisfiedLinkError

Man... this bug has got me down.

Logcat:

01-29 22:25:00.293: ERROR/AndroidRuntime(27386): FATAL EXCEPTION: main
01-29 22:25:00.293: ERROR/AndroidRuntime(27386): java.lang.IllegalStateException: Could not execute method of the activity
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at android.view.View$1.onClick(View.java:2072)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at android.view.View.performClick(View.java:2408)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at android.widget.CompoundButton.performClick(CompoundButton.java:99)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at android.view.View$PerformClick.run(View.java:8819)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at android.os.Handler.handleCallback(Handler.java:587)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at android.os.Looper.loop(Looper.java:123)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at android.app.ActivityThread.main(ActivityThread.java:4627)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at java.lang.reflect.Method.invokeNative(Native Method)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at java.lang.reflect.Method.invoke(Method.java:521)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at dalvik.system.NativeStart.main(Native Method)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386): Caused by: java.lang.reflect.InvocationTargetException
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at com.example.viewer.Viewer.denoiseSlice(Viewer.java:170)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at java.lang.reflect.Method.invokeNative(Native Method)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at java.lang.reflect.Method.invoke(Method.java:521)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at android.view.View$1.onClick(View.java:2067)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     ... 12 more
01-29 22:25:00.293: ERROR/AndroidRuntime(27386): Caused by: java.lang.UnsatisfiedLinkError: RicianDenoise
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     at com.example.viewer.Viewer.RicianDenoise(Native Method)
01-29 22:25:00.293: ERROR/AndroidRuntime(27386):     ... 16 more

Loading the Library and declaring it:

    public native void RicianDenoise(int w, int h, int p, 
        short [] s_noised_slice, double [] d_noised_slice, 
        short [] s_denoised_slice, double [] d_denoised_slice);

    static {
        System.loadLibrary("denoise");
    }

C Function:

void 
Java_com_example_viewer_Viewer_RicianDenoise (JNIEnv *env, jclass cls, jint M, 
                                              jint N, jint P, jshort * s_noised_slice,
                                              jdouble * d_noised_slice, 
                                              jshort * s_denoised_slice, 
                                              jdouble * d_denoised_slice) {
    /* ... */
}

I ran

ndk-build -B -C [project]/jni

and I can't get anything to work. Any suggestions, or experience with this issue? The invocation line in the logcat is me just trying to call the function, btw. Thank you... please be my hero :(

Arrays in java do not translate into array type pointers in C/C++, in JNI

Use this scheme on the native side to declare your arrays:
for double[] use jdoubleArray
for short[] use jshortArray

您的库是否使用其他C / C ++库,并且使用系统路径可以访问那些库吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM