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

How to push up view when custom keyboard is open from bottom
Android Lollipop view height doesn't fit screen
How to add dynamic tabs and dynamic expandable list view inside it in android?
Cookie consent in Android apps?
Fragments and progress update dialogues
Remove backgroundDimAmount from CameraPreview in DialogFragment
How to return different code and error with MockRestAdapter
FloatingActionButton do not jump up under CoordinatorLayout Android
How to implement Two-phased loads in recyclerview?
Mongodb database for Android application development
Android Custom Launcher doesn't stop the BootAnimation
Is it possible to create TouchDelegates for multiple children?
How to disable keep screen on without restarting activity
Android SurfaceView Ram Usage
How to fix “400 bad request” with uploading file on android with java HttpClient?
Using saripaar in DialogFragment

Categories

HOME
url-redirection
notepad++
assembly
object
ms-access-2016
banner
barcode
little-proxy
pega
parameter-passing
standards
mathprog
vuejs
oledb
qliksense
flask-sqlalchemy
jquery-callback
slidetoggle
amazon-quicksight
winexe
errbot
openmdao
comparable
jaws
mql
twiml
scrollview
wacom
joomla2.5
reactjs.net
xajax
protege4
reason
password-protection
health-monitoring
metawidget
plaintext
naming
linqpad
subclipse
congestion-control
bindingnavigator
file-sharing
opennms
twilio-click-to-call
lightning
remedy
arq
amq
edit
boo
gameplay-kit
cd-burning
microstation
segment-io
mapinfo
tooleap
tracker-enabled-dbcontext
text-search
finalbuilder
typemock
wso2greg
baasbox
osc
android-broadcast
ssis-data-flow
administration
sonarqube-5.0
easyrtc
punycode
imagefilter
trdion2011
create.js
personalization
ray
radiant
terminate
gae-quotas
clickbank
drupal-nodes
dtmf
bjyauthorize
qi4j
jquery-blockui
appjs
isa-swizzling
virtualpathprovider
codebase
message-passing
sifr
echo3
mathematical-notation

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