0
我想在我的應用程序中顯示PDF文件。我正在使用Pdf查看器庫(https://github.com/barteksc/AndroidPdfViewer)。我已將pdf文件放入我的資產文件夾中。但是,當我嘗試加載文件時,它顯示了這個異常:Android Pdf查看器FileNotFoundException
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
這裏是我的代碼:
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();
這裏是我的清單文件權限:
<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" />
我使用Ubuntu 12.04
有什麼辦法可以解決這個問題。
謝謝
你能否發表一些更多的細節?例如項目結構。我認爲文件路徑是錯誤的...也許嘗試添加「.pdf」到路徑... –
也看起來像你不應該把這個'src/main/assets/test'路徑。嘗試:pdfView.fromAsset(「test.pdf」)。在PDFView.fromAsset'context.getAssets()。open()'中使用http://stackoverflow.com/a/5771369/1533933,所以你不應該從源代碼文件夾 – krossovochkin
src/main/assets /測試?如果編譯機器上的文件不在'..... assets/src/main/assets /'中,並且沒有沒有外部地址就不叫'test'。那麼'FileNotFoundException是顯而易見的... – Selvin