java - Android loading files into array NullPointerException -
hi trying load set of "list" string array, , list .txt documents , want use names of files list name on display, therefore need of files in folder had created named "lists" , display them arrayadapter.
private string[] getlistnames() { //generates file containing list names file file = new file(this.getfilesdir() +file.separator +"lists"); system.out.println(file.getabsolutepath()); file lists[] = file.listfiles(); string names[] = {}; if(lists.length >0){ for(int = 0; < lists.length; ++){ names[i] = lists[i].getname(); } }else{ names[0] = "create new list"; } line of code in question according stacktrace (line 108)
if(lists.length >0){
stacktrace
03-25 04:37:16.981: e/androidruntime(2099): caused by: java.lang.nullpointerexception 03-25 04:37:16.981: e/androidruntime(2099): @ dev.shaw.myshoppingplanner.list_activity.getlistnames(list_activity.java:108)
private list<string> mylist = new arraylist<string>(); string root_sd = environment.getexternalstoragedirectory().tostring(); file = new file( root_sd + "/lists" ) ; file list[] = file.listfiles(); for( int i=0; i< list.length; i++) { mylist.add( list[i].getname() ); }
Comments
Post a Comment