please help me understand why my ArrayAdapter is not working properly, I mean it dosen't show the List of Strings that I gave as a parameter. I receive the flowing message in emulator"unfortunately 'program name' has stopped". but when I give a regular String [] array it show the items properly. here is the "problematic" code sections.
//this method is in Class DatabaseAccess, it return a record from db as List<String>
public List<String> getQuestionRecord() {
List<String> list = new ArrayList<>();
int counter = 1;
while (!cursor.isAfterLast() && (counter < 8)) {
list.add(cursor.getString(counter++));
}
if (!cursor.isAfterLast()){
cursor.moveToNext();
}else{
closeCursor();
return null;
}
return list;
}
// this method called from the MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView);
databaseAccess = DatabaseAccess.getInstance(this);
databaseAccess.open();
databaseAccess.getCursorReady();
List<String> questionRecord = databaseAccess.getQuestionRecord();
if (questionRecord != null){
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,questionRecord);
listView.setAdapter(adapter);
}else
databaseAccess.close();
}