I am working with a database with 4 columns (_id, name, scores, status), and using the following to import all rows into an arrayList.
Cursor assessmentStatus = myDbHelper.getAllTests();
assessmentStatus.moveToFirst();
while (!assessmentStatus.isAfterLast()) {
allAssessments.add(assessmentStatus.getString(1));
if(assessmentStatus.getString(3).equals("locked")) { lockedAssessments.add(assessmentStatus.getString(1)); }
assessmentStatus.moveToNext();
}
assessmentStatus.close();
The first statement (allAssessments.add...) works fine. The if statement works if I use getString(0).equals or getString(1).equals, but not if I use getString 3 or 4 - the app crashes. It also won't work if I use getColumnIndex("status").equals
Have tried cleaning the project, but can't figure out this behaviour. Any ideas why this is happening?!
UPDATE:
1) getAllTests is as follows (have also tried rawQuery SELECT * FROM ... etc
public Cursor getAllTests()
{
return myDataBase.query("assessment_tests", new String[] {"_id", "name", "scores", "status"}, null, null, null, null, null);
}
2) All fields are text fields. Uninstalling, cleaning the project and reinstalling has no effect.
3) The database is opened with:
DataBaseHelper myDbHelper = new DataBaseHelper(null);
myDbHelper = new DataBaseHelper(this);
try {
myDbHelper.openDataBase();
}catch(SQLException sqle){
throw sqle;
}
I know the database creation works fine, as I have other tables which are working perfectly...