Nadim Iqbal Nadim Iqbal - 1 month ago 30
Android Question

Android Pdf Viewer FileNotFoundException

I am trying to show pdf file in my application. I am using Pdf Viewer library(https://github.com/barteksc/AndroidPdfViewer). I have put a pdf file in my assets folder. But when I try to load the file it shows this exception:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.samsung.secautomation/com.samsung.secautomation.ui.activities.ShowPdfActivity}: com.github.barteksc.pdfviewer.exception.FileNotFoundException: src/main/assets/test does not exist


Here is my code:

com.github.barteksc.pdfviewer.PDFView pdfView=(com.github.barteksc.pdfviewer.PDFView) findViewById(R.id.pdfViewer);
pdfView.fromAsset("src/main/assets/test") //test is the pdf file name
.pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
.enableSwipe(true)
.swipeHorizontal(false)
.enableDoubletap(true)
.defaultPage(0)
.enableAnnotationRendering(false)
.password(null)
.scrollHandle(null)
.load();


Here is my permission in Manifest file:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


I am using Ubuntu 12.04

Is there any way to solve this problem.

Thank you

Answer

Replace src/main/assets/test with test. src/main/assets/test is a relative path to this file on your development machine, not in the assets as packaged on the device.

Note that I assume that you manually removed the .pdf extension from the file when you put it in src/main/assets/. If that file still has the .pdf extension, you probably need it in your code. Resources drop their extensions; assets do not.

Comments