Question

I am new to android SDK and I am trying to read from the call log to get info of the last call made with the below code.

public class MainActivity extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String sthh=getdur();
}

public String getdur(){
    String[] projection = new String[] {
            Calls.DATE
            , Calls.DURATION
            , Calls.NUMBER
    };
    ContentResolver cr = getContentResolver();
    Cursor mCur = cr.query(android.provider.CallLog.Calls.CONTENT_URI, projection, null, null, Calls.DATE + " ASC");
    mCur.moveToLast();
    String dur = mCur.getString(mCur.getColumnCount());
    mCur.close();
    return dur;
}

However, I get RuntimeException and the following in logcat.

E/CursorWindow(21773): Failed to read row 472, column 3 from a CursorWindow which has 473 rows, 3 columns.

Whats wrong with my code? Thank you very much.

Was it helpful?

Solution

Solved, just add

Cursor mCur =null;

before

mCur = cr.query.......
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top