【问题标题】:Android UnsatisfiedLinkError: parseFile using APVAndroid UnsatisfiedLinkError:使用 APV 解析文件
【发布时间】:2012-09-10 13:21:07
【问题描述】:

我正在使用(APV pdf 查看器),如此链接所示 link1 & link2

无论如何,它工作正常。但是当我通过项目更改包的名称时,它给了我以下异常:

09-10 22:02:35.936: E/AndroidRuntime(556): FATAL EXCEPTION: main
09-10 22:02:35.936: E/AndroidRuntime(556): java.lang.UnsatisfiedLinkError: parseFile
09-10 22:02:35.936: E/AndroidRuntime(556):  at cx.hell.android.pdfviewIktab.PDF.parseFile(Native Method)
09-10 22:02:35.936: E/AndroidRuntime(556):  at cx.hell.android.pdfviewIktab.PDF.<init>(PDF.java:87)
09-10 22:02:35.936: E/AndroidRuntime(556):  at cx.hell.android.pdfviewIktab.OpenFileActivity.getPDF(OpenFileActivity.java:569) 
09-10 22:02:35.936: E/AndroidRuntime(556):  at cx.hell.android.pdfviewIktab.OpenFileActivity.startPDF(OpenFileActivity.java:530)
09-10 22:02:35.936: E/AndroidRuntime(556):  at cx.hell.android.pdfviewIktab.OpenFileActivity.onCreate(OpenFileActivity.java:282)
09-10 22:02:35.936: E/AndroidRuntime(556):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-10 22:02:35.936: E/AndroidRuntime(556):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-10 22:02:35.936: E/AndroidRuntime(556):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 22:02:35.936: E/AndroidRuntime(556):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 22:02:35.936: E/AndroidRuntime(556):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 22:02:35.936: E/AndroidRuntime(556):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 22:02:35.936: E/AndroidRuntime(556):  at android.os.Looper.loop(Looper.java:123)
09-10 22:02:35.936: E/AndroidRuntime(556):  at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 22:02:35.936: E/AndroidRuntime(556):  at java.lang.reflect.Method.invokeNative(Native Method)
09-10 22:02:35.936: E/AndroidRuntime(556):  at java.lang.reflect.Method.invoke(Method.java:521)
09-10 22:02:35.936: E/AndroidRuntime(556):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 22:02:35.936: E/AndroidRuntime(556):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 22:02:35.936: E/AndroidRuntime(556):  at dalvik.system.NativeStart.main(Native Method)

这是类(PDF.java):

package cx.hell.android.pdfviewIktab;

import java.io.File;
import java.io.FileDescriptor;
import java.util.List;
import cx.hell.android.lib.pagesview.FindResult;


public class PDF {
static {
    System.loadLibrary("pdfview2");
}


public static class Size implements Cloneable {
    public int width;
    public int height;

    public Size() {
        this.width = 0;
        this.height = 0;
    }

    public Size(int width, int height) {
        this.width = width;
        this.height = height;
    }

    public Size clone() {
        return new Size(this.width, this.height);
    }
}


private int pdf_ptr = -1;
private int invalid_password = 0;

public boolean isValid() {
    return pdf_ptr != 0;
}

public boolean isInvalidPassword() {
    return invalid_password != 0;
}

synchronized private native int parseFile(String fileName, int box, String password);

synchronized private native int parseFileDescriptor(FileDescriptor fd, int box, String password);

public PDF(File file, int box) {

 // this is the line of (cx.hell.android.pdfviewIktab.OpenFileActivity.getPDF(OpenFileActivity.java:569))
    this.parseFile(file.getAbsolutePath(), box, "");
}

public PDF(FileDescriptor file, int box) {
    this.parseFileDescriptor(file, box, "");
}

synchronized public native int getPageCount();

synchronized public native int[] renderPage(int n, int zoom, int left, int top, 
        int rotation, boolean gray, boolean skipImages, PDF.Size rect);

synchronized public native int getPageSize(int n, PDF.Size size);

synchronized public native List<FindResult> find(String text, int page);

synchronized public native void clearFindResult();

synchronized public native List<FindResult> findOnPage(int page, String text);

synchronized private native void freeMemory();

public void finalize() {
    try {
        super.finalize();
    } catch (Throwable e) {
    }
    this.freeMemory();
}
}

有什么帮助吗?提前致谢。

【问题讨论】:

    标签: android android-intent pdfview apvpdf


    【解决方案1】:

    此错误表示 Android Dalvik 虚拟机找不到给定 Java 类/方法所需的本机库。请正确构建本机库。如果本机库已正确创建并且您确定它应该可以毫无问题地加载,那么它要么是 Android/Dalvik 错误,要么是 NDK 错误……但这极不可能。这个问题在 APV 的用户群里被问过很多次,通常是因为问这个问题的人不了解 JNI 的基础知识。

    如果您仍然不知道如何解决这个问题,我建议为 Java 和 Android(使用 android-ndk)创建基本的 JNI“hello, world”应用程序并尝试一下。这应该会为您解决问题。

    抱歉,这个错误与 APV 本身无关,APV 在这里没有做任何特殊的神秘魔法,它只是使用了许多其他应用程序使用的标准成熟技术 (JNI)。

    Java 如何查找和调用本机方法的说明:http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp679。

    您粘贴的代码已将 pdfview 包名称更改为 pdfviewIktab。确保您已相应地更改了 JNI (C) 函数名称。

    【讨论】:

    • 是的,我将 pdfview2.c 中的包名称更改为 Java_cx_hell_android_pdfviewIktab 而不是 Java_cx_hell_android_pdfview,但仍然给我同样的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 2016-03-04
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    • 2018-07-03
    相关资源
    最近更新 更多