【发布时间】:2015-05-19 05:23:03
【问题描述】:
所以现在我一直在尝试实现 joanzapata 的 pdfview,来自: "http://joanzapata.com/android-pdfview/"
主要关注的是 API-10+ 友好。
无论我做什么,我都会遇到一个或另一个错误,不知何故,现在我的项目正在运行(显然)但是当我找到我的 PDF 文件并尝试使用与项目示例相同的代码加载它时,我得到了以下问题。
首先是我的代码:
...
//File currentLoc = new File(string_pdfLoc);
...
//File thePdf = currentLoc;
//thePdf is of type File
if( thePdf != null ) {
Log.d("MyDebug", "1/3 File not Null");
if( thePdf.exists() ) {
Log.d("MyDebug", "2/3 File exists");
if (thePdf.canRead()) {
Log.d("MyDebug", "3/3 File can be Read");
Log.d("MyDebug", "thePDF: " + thePdf.getAbsolutePath());
//------ PDF should Exist ----------------------
Log.d("MyDebug","Should now load thePDFView");
//pdfView.fromAsset(pdfName)
Log.d("MyDebug","thePDFView.fromAsset");
thePDFView.fromAsset(thePdf.getAbsolutePath() );
Log.d("MyDebug","thePDFView.fromAsset.load");
thePDFView.fromAsset(thePdf.getAbsolutePath() ).load();
} else {
Log.d("MyDebug", "File exists, but cannot Read");
}
}else{
Log.d("MyDebug", "File != null, but !exists");
}
}else{
Log.d("MyDebug","thePDF, is still null");
}
现在出现错误,请注意“公司”和“项目名称”通常命名不同,但仍然是小写字符,但我隐藏了它们的名称。
Found a PDF File
D/MyDebug? 1/3 File not Null
D/MyDebug? 2/3 File exists
D/MyDebug? 3/3 File can be Read
D/MyDebug? thePDF: /storage/emulated/0/Android/data/com.projectname.company.projectname/files/ThisisaPDF.pdf
D/MyDebug? Should now load thePDFView
D/MyDebug? thePDFView.fromAsset
D/AndroidRuntime? Shutting down VM
W/dalvikvm? threadid=1: thread exiting with uncaught exception (group=0x41942da0)
E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.projectname.company.projectname, PID: 9591
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.projectname.tpub.projectname/com.projectname.company.projectname.PdfViewActivity}: com.joanzapata.pdfview.exception.FileNotFoundException: /storage/emulated/0/Android/data/com.projectname.company.projectname/files/ThisisaPDF.pdf does not exist.
...
Caused by: com.joanzapata.pdfview.exception.FileNotFoundException: /storage/emulated/0/Android/data/com.projectname.company.projectname/files/ThisisaPDF.pdf does not exist.
at com.joanzapata.pdfview.PDFView.fromAsset(PDFView.java:905)
at com.projectname.company.projectname.PdfViewActivity.onCreate(PdfViewActivity.java:88)
这是我在清单中的权限:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
这是我的 Gradle(app).Build 文件:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.joanzapata.pdfview:android-pdfview:1.0.+@aar'
}
据我所知,应该引入插件,否则我预计会出现一些错误,例如我过去遇到的关于 Gradle 的错误。
欢迎任何建议,我会经常检查,任何建议我都可以轻松尝试并回复。
【问题讨论】:
标签: android android-studio filenotfoundexception file-exists