Skip to content
Advertisement

Trying to populate listview with array text

I have a listview that I am trying to populate by changing the text of the row xml to the file paths in the folder (so I can later perform operations on the files. I am getting a crash upon starting the activity.

My code: FileView.java

JavaScript

activity_file_view.xml

JavaScript

row.xml

JavaScript

I am getting this error:

JavaScript

Appears to be a null object reference, but I am unsure how to solve

Advertisement

Answer

The root of your issue is stringList.add(fileList[i].getName()); where stringList is not initialized. so try the following,

JavaScript

Edit:

Though your adapter seems to work, the inflation logic is wrong as your arent recycling the views instead just creating new views for every data item to be displayed, so try the following instead

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement