2

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

6
  • Can you post some more details?? For example the Project structure. I think the file path is wrong... maybe try to add ".pdf" to the path... Commented Oct 31, 2016 at 10:52
  • 2
    Also looks like you shouldn't put this 'src/main/assets/test' path. try: pdfView.fromAsset("test.pdf"). Inside the PDFView.fromAsset 'context.getAssets().open()' is used stackoverflow.com/a/5771369/1533933 so you should not write path from your source code folder Commented Oct 31, 2016 at 10:56
  • src/main/assets/test ? if file on compile machine is not in .....assets/src/main/assets/ and is not called test without ext. then `FileNotFoundException is obvious ... Commented Oct 31, 2016 at 10:56
  • pdfView.fromAsset() take only String as parameter thats why I put the file location. The application structure is Project-->app-->src-->main-->assets-->test.pdf Commented Oct 31, 2016 at 11:09
  • assets are in a "pre-defined" location, and do not refer to your build path. same is true for all the Android asset files. Commented Oct 31, 2016 at 11:23

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.