1

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.

1 Answer 1

1

Solved, just add

Cursor mCur =null;

before

mCur = cr.query.......
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.