samedi 4 avril 2015

Android - Database - length=0; index=5

hello world :D how are you


I need to know what is the problem with this code??



public String getLastDate(){
SQLiteDatabase database = lecturesDB.getReadableDatabase();
try {
String [] a = {DATE};
Cursor cursor = database.query(LECTURES_TABLE, a, null, null, null, null, null);
int i = cursor.getColumnIndex(DATE);
cursor.moveToFirst();
String ld = cursor.getString(i);//Thu, 26 Mar 2015 17:19:56
DateFormat format = new SimpleDateFormat("dd MMM yyyy hh:mm:ss ");
Date date = format.parse(ld.substring(5));
while (cursor.moveToNext()){
String c = cursor.getString(i);
Log.e("Mayiaz",ld+" "+c);
if (format.parse(c.substring(5)).getTime()>date.getTime()){
date = format.parse(c.substring(5));
ld = c;
}
}
return ld;
}catch (Exception e) {Log.e("Mayiaz",e.getMessage());return "";}
finally {
database.close();
}
}


its return "" and the exception show this message : "04-04 19:55:45.702 1478-1634/com.mine.rbt E/Mayiaz﹕ length=0; index=5"


and thanks :)


Aucun commentaire:

Enregistrer un commentaire