我正在尝试以文本的形式在数据库中以毫秒为单位节省时间。
long time= System.currentTimeMillis()
在我尝试检索它并转换为日期之后:
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();
代码崩溃然后我试图初始化“a”。但没有它,它就有效。
在字符串结果是:
1433064363251 - 14330643544443
我究竟做错了什么?请帮忙。提前完成。
答案 0 :(得分:2)
moveToFirst
方法应该是第一个,然后你可以访问Cursor值。
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();