使用Sqlite Android提取日期时间很麻烦

使用Sqlite Android提取日期时间很麻烦,android,string,sqlite,datetime,Android,String,Sqlite,Datetime,这是我的代码: String sqlcomment="SELECT createdBy, text, documentPath, editedDate, actualityCommentID, actualityID FROM ActualityComment WHERE actualityID="+actual.getCode(); Cursor curcomment; SQLiteDatabase dbase = openOrCreateDatabase("leymaxdb.sqlite

这是我的代码:

String sqlcomment="SELECT createdBy, text, documentPath, editedDate, actualityCommentID, actualityID FROM ActualityComment WHERE actualityID="+actual.getCode();

Cursor curcomment;
SQLiteDatabase  dbase = openOrCreateDatabase("leymaxdb.sqlite",SQLiteDatabase.CREATE_IF_NECESSARY,null);

 curcomment = dbase.rawQuery(sqlcomment, null);
 int maxid=0;
     if (curcomment.moveToFirst()) {
        do
        {
           System.out.println(curcomment.getString(3).toString());
        }while (curcomment.moveToNext());

    }

    dbase.close();
错误在这一行,因为我需要从数据库打印EditeDate,这是DateTime

System.out.println(curcomment.getString(3).toString());
这就是android的错误:

java.lang.NullPointerException

检查actual.getCode()的值是多少,并检查游标是否为null。然后访问它。数据库可能不包含该查询的任何记录


将日期作为字符串获取后,将该值传递给SimpleDataFormat以生成日期对象

第一次检查,是否创建了数据库? 有没有价值

通过从文件资源管理器获取.db文件来实现

一旦db有了值

然后从光标读取日期值并显示如下:

Date date = new Date(curcomment.getString(3));
DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
mydate.setText("Time: " + dateFormat.format(date));

调试并检查curcomment.getString(3)的值。它可能返回空值。
editedDate
数据类型为
Date
String
?@Lokesh无curcomment。getString(3)不是null@MD数据类型是DateTime,希望它能帮助您。