Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 02-14 00:13:10.279 32478-32478/com.example.chris.sunil_gupta W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x415998e0)
- 02-14 00:13:10.289 32478-32478/com.example.chris.sunil_gupta E/AndroidRuntime﹕ FATAL EXCEPTION: main
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chris.sunil_gupta/com.example.chris.sunil_gupta.MainActivity}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 500
- package com.example.chris.sunil_gupta;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import android.app.Activity;
- import android.content.Context;
- import android.database.Cursor;
- import android.os.Bundle;
- import android.provider.CallLog;
- import android.widget.ListView;
- public class MainActivity extends Activity {
- private List <CallData>list = new ArrayList<CallData>();
- private Context context=null;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- ListView listview;
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- context=this;
- listview=(ListView)findViewById(R.id.ListView_CallData);
- getCallDetails();
- CustomAdapter adapter = new CustomAdapter(MainActivity.this, list);
- listview.setAdapter(adapter);
- }
- public void getCallDetails()
- {
- // cursor1 gets all the items in the calllog and arranges them from newest call down
- Cursor cursor1 = getContentResolver().query(
- CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DATE + " DESC");
- //looks like all the cell values in the calllog database are integers
- int number = cursor1.getColumnIndex( CallLog.Calls.NUMBER );
- int type = cursor1.getColumnIndex( CallLog.Calls.TYPE );
- int date = cursor1.getColumnIndex( CallLog.Calls.DATE);
- int duration = cursor1.getColumnIndex( CallLog.Calls.DURATION);
- //declare some new variables here; we're going to convert the integers into these
- String callType;
- String phoneNumber;
- String callDate;
- String callDuration;
- Date callDateTime;
- //go through all the rows in the db and convert the values to strings or whatever
- while (cursor1.moveToNext())
- {
- phoneNumber = cursor1.getString(number);
- callType = cursor1.getString(type);
- callDate = cursor1.getString(date);
- callDateTime = new Date(Long.valueOf(callDate));
- callDuration = cursor1.getString(duration);
- // the string cType will give us text of either outgoing, incoming or missed
- String cType = null;
- int cTypeCode = Integer.parseInt(callType);
- switch(cTypeCode)
- {
- case CallLog.Calls.OUTGOING_TYPE:
- cType = "OUTGOING";
- break;
- case CallLog.Calls.INCOMING_TYPE:
- cType= "INCOMING";
- break;
- case CallLog.Calls.MISSED_TYPE:
- cType = "MISSED";
- break;
- }
- CallData calldata=new CallData(cType, phoneNumber, callDateTime, callDuration);
- list.add(calldata);
- }
- cursor1.close();
- }
- }
- int type = cursor1.getColumnIndex( CallLog.Calls.TYPE);
- String type = cursor1.getString(cursor1.getColumnIndex(CallLog.Calls.TYPE));
- switch (Integer.parseInt(type))
- package com.example.chris.sunil_gupta;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import android.app.Activity;
- import android.content.Context;
- import android.database.Cursor;
- import android.os.Bundle;
- import android.provider.CallLog;
- import android.widget.ListView;
- public class MainActivity extends Activity {
- private List <CallData>list = new ArrayList<CallData>();
- private Context context=null;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- ListView listview;
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- context=this;
- listview=(ListView)findViewById(R.id.ListView_CallData);
- getCallDetails();
- CustomAdapter adapter = new CustomAdapter(MainActivity.this, list);
- listview.setAdapter(adapter);
- }
- public void getCallDetails()
- {
- // cursor1 gets all the items in the calllog and arranges them from newest call down
- Cursor cursor1 = getContentResolver().query(
- CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DATE + " DESC");
- //looks like all the cell values in the calllog database are integers
- int number = cursor1.getColumnIndex( CallLog.Calls.NUMBER );
- // int type = cursor1.getColumnIndex( CallLog.Calls.TYPE );
- String type = cursor1.getString(cursor1.getColumnIndex(CallLog.Calls.TYPE));
- int date = cursor1.getColumnIndex( CallLog.Calls.DATE);
- int duration = cursor1.getColumnIndex(CallLog.Calls.DURATION);
- //declare some new variables here; we're going to convert the integers into these
- String phoneNumber;
- String callDate;
- String callDuration;
- Date callDateTime;
- //go through all the rows in the db and convert the values to strings or whatever
- while (cursor1.moveToNext())
- {
- phoneNumber = cursor1.getString(number);
- callDate = cursor1.getString(date);
- callDateTime = new Date(Long.valueOf(callDate));
- callDuration = cursor1.getString(duration);
- // the string cType will give us text of either outgoing, incoming or missed
- String cType = null;
- switch (Integer.parseInt(type))
- {
- case CallLog.Calls.OUTGOING_TYPE:
- cType = "OUTGOING";
- break;
- case CallLog.Calls.INCOMING_TYPE:
- cType= "INCOMING";
- break;
- case CallLog.Calls.MISSED_TYPE:
- cType = "MISSED";
- break;
- }
- CallData calldata=new CallData(cType, phoneNumber, callDateTime, callDuration);
- list.add(calldata);
- }
- cursor1.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement