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

increase resolution of image in android programming
can't get gps location
Android: How to get JSON object from Zomato API?
Android deep linking schema: match both http and https
How to re-install production Android app without leaving the beta test?
OpenCV 3.1.0 in android studio (NDK) - updateMotionHistory unresolved
Android Ring Shape with divisions
Firebase loading data for android quiz app
Android soft keyboard hides RecyclerView
How to make android debug mode share the same signature across different machines
Vertical centering imageview in relativelayout
Android Videoview strech not fit in portrait mode
I want to send an message from my Android Watch to my Android Phone. Other way around is working
Backendless Messages.registerDevice return 'success' but device is not listed
basic programming help needed for Firebase, Android
parse the html and show it in webview android

Categories

HOME
algorithm
phantom-dsl
fuelux
ecmascript-6
mjml
saml-2.0
gembox-spreadsheet
rcloud
jquery-ui-sortable
reactive-programming
ipmitool
radgridview
esoteric-languages
dreamweaver
asp.net-mvc-viewmodel
google-picker
xmonad
soci
gmm
solrcloud
symbols
asciidoctor-pdf
xcode-ui-testing
stackexchange
jackson-modules
jasmine-node
oculus
paperjs
iis-express
send
autolisp
laravel-eloquent
clickjacking
google-knowledge-graph
amazon-ses
bc
apns-php
p4merge
setup.py
visa
file-sharing
drupal-theming
uiimage
puredata
flask-restful
clarifai
geotiff
tinymce-3
static-cast
monkey
vibrate
javafx-css
visual-studio-2008-sp1
cudd
pure-css
pytables
jodd
rspec2
mapinfo
simevents
swizzling
kango-framework
concept-insights
assertion
qt5.2
themoviedb-api
fiware-monitoring
text-search
zscript
amiga
exceldatareader
beatsmusic
big-ip
device-tree
unix-socket
bin
hibernate-entitymanager
video-codecs
twisted.web
redis-py
sentestingkit
subproject
apache-whirr
multiplexing
httponly
google-floodlight
webdev.webserver
lr
timthumb
collectionviewsource
rowlex
hbm2java
wysiwym
blind

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