Reputation: 139
I am trying to save time in milliseconds in my database as text.
long time= System.currentTimeMillis()
After i am trying to retrieve it and convert to date like this:
SQLiteDatabase db = dbHelper.getWritableDatabase();
Cursor c = db.query("MovementTable", null, null, null, null, null, null);
String str = "";
long a = c.getLong(0);
if (c.moveToFirst()) {
do {
if (!c.getString(6).equals("0"))
str = str + c.getLong(0) + " - " +c.getLong(1) + CheckPoint(new LatLng(c.getDouble(2),c.getDouble(3)))
+ " to " + CheckPoint(new LatLng(c.getDouble(4),c.getDouble(5))) + " " + c.getString(6) + "\n";
} while (c.moveToNext());
}
c.close();
Text.setText(str);
dbHelper.close();
Code crashes then i am trying to initialize "a". But without it, it works.
In string result is:
1433064363251 - 14330643544443
What am i doing wrong? Please help. Thanx in advance.
Upvotes: 0
Views: 69
Reputation: 4569
moveToFirst
method should be first, then you can access to Cursor values.
if (c.moveToFirst()) {
long a = c.getLong(0);
do {
if (!c.getString(6).equals("0"))
str = str + c.getLong(0) + " - " +c.getLong(1) + CheckPoint(new LatLng(c.getDouble(2),c.getDouble(3)))
+ " to " + CheckPoint(new LatLng(c.getDouble(4),c.getDouble(5))) + " " + c.getString(6) + "\n";
} while (c.moveToNext());
}
c.close();
Upvotes: 2