I am trying to create an app that searches my Download folder for the most current version of a specific file and then returns the path to that file. I keep getting a NullPointerException
when I try looking at either the file array or string array with the file names. The null point comes when I call downloadList.length;
. I have also tried while(download[i] != null) {
but I still get NullPointerException
. I am fairly new to app programming and have build a few apps, but none of them access public files. Any help is greatly appreciated.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String dlDir = Environment.DIRECTORY_DOWNLOADS;
Log.d("Dir", dlDir);
File downloadDir = new File(dlDir);
Log.d("Dir", "Found the Directory");
String[] downloadList = downloadDir.list();
// File[] downloadList = downloadDir.listFiles();
Log.d("Dir", "Created the list");
int len = downloadList.length;
while (int i = 0; i < len; i++) {
DoStuff
}
}
}