You have a few problems in your code. First of all, you call cursor.moveToFirst()twice in normal mode:
if (cursor != null && cursor.moveToFirst())
cursor.moveToFirst();
In addition, you are trying to get data from the cursor, even if the cursor is empty or it has not received data:
if (cursor != null && cursor.moveToFirst())
cursor.moveToFirst();
Lirik lirik = new Lirik(cursor.getString(1),
cursor.getString(2)); // <-- cursor can be null here
In any case, you leave resources open. You never close cursor, and if there is any problem, dbalso does not close. I suggest rewriting your function getLirik()as follows:
public Lirik getLirik(final String id) {
Lirik lirik = null;
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = this.getReadableDatabase();
cursor = db.query(TABLE_MUPUH, new String[] { KEY_ID, JUDUL,
KEY_MUPUH }, KEY_ID + "=?", new String[] { id }, null,
null, null);
if (cursor != null && cursor.moveToFirst()) {
lirik = new Lirik(cursor.getString(1), cursor.getString(2));
}
} catch (final Exception e) {
} finally {
cursor.close();
db.close();
}
return lirik;
}
, , getLirik() null, ViewMupuh.onCreate() , :
textJudul = (TextView) findViewById(R.id.judul_details);
textLirik = (TextView) findViewById(R.id.lirikdetails);
DBHelper db = new DBHelper(this);
Lirik lirik = db.getLirik(position);
if (lirik != null) {
textJudul.setText(lirik.getJudul());
textLirik.setText(lirik.getLirik());
}
, , , , (, ?)