android


Want to List PDF files from Download Folder. Getting Error


I want to list PDF files from Downloads folder, but I am getting error of null point while getting files. I am providing my code below. For displaying pdf file I am using com.github.barteksc:android-pdf-viewer:1.4.0' library.
package com.tutorials.hp.gridviewpdf;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.GridView;
import java.io.File;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final GridView gv= (GridView) findViewById(R.id.gv);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
gv.setAdapter(new CustomAdapter(MainActivity.this,getPDFs()));
}
});
}
private ArrayList<PDFDoc> getPDFs()
{
ArrayList<PDFDoc> pdfDocs=new ArrayList<>();
//TARGET FOLDER
File downloadsFolder= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
PDFDoc pdfDoc;
if(downloadsFolder.exists())
{
//GET ALL FILES IN DOWNLOAD FOLDER
File[] files=downloadsFolder.listFiles();
//LOOP THRU THOSE FILES GETTING NAME AND URI
for (int i=0;i<files.length;i++)
{
File file=files[i];
if(file.getPath().endsWith("pdf"))
{
pdfDoc=new PDFDoc();
pdfDoc.setName(file.getName());
pdfDoc.setPath(file.getAbsolutePath());
pdfDocs.add(pdfDoc);
}
}
}
return pdfDocs;
}
}
Here is my logcat

Related Links

Fit bit API :: Transfer heart rate data of user from fit bit supported device in to own android application
Android Resource not found exception when trying to add a datepicker to layout
Running broadcast receiver on a separate thread
How to stack multiple push notifications using GCM Client?
Rotate clip art in android
PMD, checkstyle and findbugs android setup
Getting Image from gallery in android
Proguard keep interface method variable names
Android ArrayAdapter Filter not updating size leaving empty cells
What is RecyclerView.Adapter's counterpart of ListView.Adpater.isEnabled()
Android Studio - Display data from database to TextView
Download .apk with DownloadManager
List<Address> addresses = geoCoder.getFromLocationName(“Mumbai” , 5); returns zeo
get all facebook likes without pagination in android
Module per Fragment / Activity in Dagger
Android Service not stopping self

Categories

HOME
cobalt
fuelux
components
bitbucket-api
iis-6
fabric.io
project
reactive-programming
resultset
cmdb
xcodebuild
speech-synthesis
event-sourcing
mvc-mini-profiler
jersey-1.0
shortest-path
jmp
enterprise-miner
database-connection
simpleitk
imagemap
scriptella
flask-sqlalchemy
comparator
google-api-client
ckfinder
siri
motion-detection
progress-bar
sinch
paperjs
subclass
openmdao
browser-sync
tizen-tv
scrollview
spring-security4
clickjacking
least-squares
hivemq
alphabetical
modernizr
filesystemwatcher
ods
branching-and-merging
linqpad
claims
congestion-control
uiimage
procfile
opencmis
flask-restful
textsum
proget
robomongo
tinkerpop
compiler-design
cup
pdf-conversion
gpg-signature
template-toolkit
cmp
rmongo
choice
slackware
omxplayer
pacemaker
microstation
latin
envi
spring-cloud-feign
file-uri
observablecollection
clipboard.js
stream-processing
project-organization
kiosk
jnlua
state-restoration
decimalformat
grgit
xvim
uncompress
telepat
java-security
uncaught-typeerror
rmysql
websphere-esb
oocss
route-provider
asplinkbutton
resource-management
extreme-programming
mkv
web-farm
saleslogix
virtualpathprovider
role
jquery-tools
pylucene
appledoc
silent
nstokenfield
echo3
entitykey
technical-debt

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App