Reputation: 31
So for sometime now ive been trying to implement joanzapata's pdfview, from: "http://joanzapata.com/android-pdfview/"
The main focus is for this to be API-10+ Friendly.
No matter what I do I keep getting one error or another, somehow now I have the project working (apparently) but when I find my PDF file and try and load it with the same code as the projects Sample, I get the following issue.
Firstly my code:
...
//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");
}
And now the error, take note that "company" & "projectname" are normally named differently but still lower-case charcters, but I have hidden their name.
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)
Here is the permission I have in the Manifest:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
Here is my Gradle(app).Build file:
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'
}
So as far as I can tell, the Plugin should be being brought in, otherwise I would expect some errors such as the ones I have had in the past regarding Gradle.
Any advice is most welcome, I will be checking this often, any suggestions I can easily try and respond.
Upvotes: 0
Views: 1075
Reputation: 1006674
Based on my reading of the source code, fromAsset()
is for reading in an asset. Try fromFile()
instead.
Upvotes: 1