Pregunta

I'm using (APV pdf viewer) as shown in this links link1 & link2

Anyway it works fine. But when I changed the name of the packages in through the project, it gives me the following Exception:

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)

this is the class (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();
}
}

Any Help please?? Thanks in Advance.

¿Fue útil?

Solución

This error means that Android Dalvik Virtual Machine can't find native library required by given Java class/method. Please build native library correctly. If native library has been created correctly and you are sure that it should load without problem, then it's either Android/Dalvik bug or NDK bug... however this is extremely unlikely. This question has been asked many times on APV's user group and usually it's because person asking this question doesn't know basics of JNI.

If you still don't know how to fix this problem, I'd suggest creating basic JNI "hello, world" application for Java and then for Android (using android-ndk) and playing around with it a bit. This should clear things up for you.

Sorry, but this error has nothing to do with APV itself, APV does not do any specfial cryptic magic here, it's just using standard proven technology (JNI) as used by a lot of other apps.

Description of how Java finds and calls native methods: http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp679.

Code you've pasted has pdfview package name changed to pdfviewIktab. Make sure you've changed JNI (C) function names accordingly.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top