I use the following method in my database class. It is not working and i do not see where the problem is. Maybe someone can help me.
public ArrayList<Profile> getAllProfile() {
db = this.getWritableDatabase();
Profile profile = new Profile();
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_USER, null);
ArrayList<Profile> profiles = new ArrayList<>();
if (cursor!=null){
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext() ){
profile.setId(cursor.getInt(cursor.getColumnIndex(ID)));
profile.setFirstName(cursor.getString(cursor.getColumnIndex(FIRST_NAME)));
profile.setLastName(cursor.getString(cursor.getColumnIndex(LAST_NAME)));
profile.setFatherName(cursor.getString(cursor.getColumnIndex(FATHER)));
profile.setAge(cursor.getInt(cursor.getColumnIndex(AGE)));
profile.setEmail(cursor.getString(cursor.getColumnIndex(EMAIL)));
profile.setGender(cursor.getInt(cursor.getColumnIndex(GENDER)));
profile.setPhoneNumber(cursor.getString(cursor.getColumnIndex(PHONE_NUMBER)));
profiles.add(profile);
App.myLog("is : " +profile.getFirstName());
}
cursor.close();
return profiles;
}
cursor.close();
return null;
}