打开pdf时出现NullPointer异常(MUPDF Android)

时间:2014-07-16 12:24:28

标签: java android pdf nullpointerexception rendering

我有一个库项目,它是MUPDF渲染库。我正在使用名为OPENER的项目,要求图书馆项目显示pdf。像这样:

String s= Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/Download/Adobe Reader/Getting Started with Adobe Reader.pdf";
Uri uri = Uri.parse(s);

Intent intent = new Intent(getBaseContext(), MuPDFActivity.class);

intent.setAction(Intent.ACTION_VIEW);

intent.setData(uri);





startActivity(intent);

我认为pdf确实打开了(我无法看到它),因为Logcat说:

  

07-16 12:21:02.678:D / dalvikvm(2317):没有找到JNI_OnLoad   /data/data/com.example.opener/lib/libmupdf.so 0xa6ac31c8,跳过   init 07-16 12:21:02.690:E / libmupdf(2317): 打开文档 ... 07-16   12:21:02.706:I / alert(2317):alert_init 07-16 12:21:02.706:   E / libmupdf(2317): 完成! 07-16 12:21:02.738:D / dalvikvm(2317):   GC_CONCURRENT释放181K​​,3%免费8176K / 8391K,暂停13ms + 0ms,总计   22毫秒

但是在上面的消息之后,我得到一个nullpointerException。以下是完整的错误消息:

07-16 12:21:02.830: E/AndroidRuntime(2317): FATAL EXCEPTION: main
07-16 12:21:02.830: E/AndroidRuntime(2317): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.opener/com.artifex.mupdflib.MuPDFActivity}: java.lang.NullPointerException
07-16 12:21:02.830: E/AndroidRuntime(2317):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at android.os.Looper.loop(Looper.java:137)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at android.app.ActivityThread.main(ActivityThread.java:4745)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at java.lang.reflect.Method.invokeNative(Native Method)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at java.lang.reflect.Method.invoke(Method.java:511)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at dalvik.system.NativeStart.main(Native Method)
07-16 12:21:02.830: E/AndroidRuntime(2317): Caused by: java.lang.NullPointerException
07-16 12:21:02.830: E/AndroidRuntime(2317):     at com.artifex.mupdflib.CallbackApplication$MuPDFCallbackClass.sendGaiView(CallbackApplication.java:16)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at com.artifex.mupdflib.MuPDFActivity.updatePageNumView(MuPDFActivity.java:966)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at com.artifex.mupdflib.MuPDFActivity.access$5(MuPDFActivity.java:949)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at com.artifex.mupdflib.MuPDFActivity$4.onMoveToChild(MuPDFActivity.java:430)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at com.artifex.mupdflib.ReaderView.setDisplayedViewIndex(ReaderView.java:94)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at com.artifex.mupdflib.MuPDFActivity.createUI(MuPDFActivity.java:654)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at com.artifex.mupdflib.MuPDFActivity.onCreate(MuPDFActivity.java:396)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at android.app.Activity.performCreate(Activity.java:5008)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-16 12:21:02.830: E/AndroidRuntime(2317):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)

问题是什么,我哪里错了?

1 个答案:

答案 0 :(得分:3)

String s=Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/Download/AdobeReader/Getting Started with Adobe Reader.pdf";
Uri uri = Uri.parse(s);

Intent intent = new Intent(getBaseContext(), MuPDFActivity.class);

intent.setAction(Intent.ACTION_VIEW);

intent.setData(uri);



//if document protected with password
intent.putExtra("password", "PDF document password");

//if you need highlight link boxes
intent.putExtra("linkhighlight", true);

//if you don't need device sleep on reading document
intent.putExtra("idleenabled", false);

//document name
intent.putExtra("docname", "PDF document file name");




startActivity(intent);