I am trying to fetch all sms(both inbox,sent sms) in android. I have tried with these
Uri uri_sent = Uri.parse("content://sms");
Cursor c_sent = getContentResolver().query(uri_sent, null, null, null,
null);
startManagingCursor(c_sent);
// Read the inbox sms data and store it in the list
if (c_sent.moveToFirst()) {
for (int i = 0; i < c_sent.getCount(); i++) {
SmsDataClass sms = new SmsDataClass();
sms.setAddress(c_sent.getString(
c_sent.getColumnIndexOrThrow("address")).toString());
sms.setBody(c_sent.getString(
c_sent.getColumnIndexOrThrow("body")).toString());
sms.setDate(c_sent.getString(
c_sent.getColumnIndexOrThrow("date")).toString());
sms.set_id(c_sent
.getString(c_sent.getColumnIndexOrThrow("_id"))
.toString());
sms.setType(c_sent.getString(
c_sent.getColumnIndexOrThrow("type")).toString());
// sms.setTitle(c.getString(c.getColumnIndexOrThrow("title")).toString());
all_sms_data.add(sms);
c_sent.moveToNext();
}
} else
c_sent.close();
it sometimes works but it doesn't work regularly. Sometimes it shows null pointer exception on c_sent.getColumnIndexOrThrow("address"),c_sent.getColumnIndexOrThrow("body") ...
.
What is the problem ??? I dont understand. Before oneday it works fine when today i have nullpointer exception. Why???