0

this is my code :

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();

the error is in this line because i need to print editedDate from database and this is DateTime

System.out.println(curcomment.getString(3).toString());

And this is the android error :

java.lang.NullPointerException
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
slama007
  • 1,273
  • 2
  • 18
  • 34

2 Answers2

0

check what the value of actual.getCode() is and also check for cursor that cursor is null or not. then access it . may be database does not contain any record for that query.

after getting date as string pass that value to SimpleDateFormat to make the date object.

Waqar Ahmed
  • 5,005
  • 2
  • 23
  • 45
0

First check, database created? having value or not?

do it by taking .db file from file explorer.

once db having values,

then read date value from cursor and display like below:

Date date = new Date(curcomment.getString(3));
DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
mydate.setText("Time: " + dateFormat.format(date));
Lokesh
  • 5,180
  • 4
  • 27
  • 42