Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. 02-14 00:13:10.279 32478-32478/com.example.chris.sunil_gupta W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x415998e0)
  2. 02-14 00:13:10.289 32478-32478/com.example.chris.sunil_gupta E/AndroidRuntime﹕ FATAL EXCEPTION: main
  3. 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
  4.  
  5. package com.example.chris.sunil_gupta;
  6.  
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9. import java.util.List;
  10.  
  11. import android.app.Activity;
  12. import android.content.Context;
  13. import android.database.Cursor;
  14. import android.os.Bundle;
  15. import android.provider.CallLog;
  16. import android.widget.ListView;
  17.  
  18. public class MainActivity extends Activity {
  19.  
  20.  
  21.  
  22. private List <CallData>list = new ArrayList<CallData>();
  23. private Context context=null;
  24. @Override
  25. protected void onCreate(Bundle savedInstanceState) {
  26.  
  27. ListView listview;
  28.  
  29. super.onCreate(savedInstanceState);
  30. setContentView(R.layout.activity_main);
  31.  
  32.  
  33.  
  34. context=this;
  35.  
  36. listview=(ListView)findViewById(R.id.ListView_CallData);
  37.  
  38. getCallDetails();
  39. CustomAdapter adapter = new CustomAdapter(MainActivity.this, list);
  40. listview.setAdapter(adapter);
  41. }
  42.  
  43. public void getCallDetails()
  44. {
  45.  
  46.  
  47. // cursor1 gets all the items in the calllog and arranges them from newest call down
  48. Cursor cursor1 = getContentResolver().query(
  49. CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DATE + " DESC");
  50.  
  51. //looks like all the cell values in the calllog database are integers
  52. int number = cursor1.getColumnIndex( CallLog.Calls.NUMBER );
  53. int type = cursor1.getColumnIndex( CallLog.Calls.TYPE );
  54. int date = cursor1.getColumnIndex( CallLog.Calls.DATE);
  55. int duration = cursor1.getColumnIndex( CallLog.Calls.DURATION);
  56.  
  57. //declare some new variables here; we're going to convert the integers into these
  58. String callType;
  59. String phoneNumber;
  60. String callDate;
  61. String callDuration;
  62. Date callDateTime;
  63.  
  64. //go through all the rows in the db and convert the values to strings or whatever
  65. while (cursor1.moveToNext())
  66. {
  67.  
  68. phoneNumber = cursor1.getString(number);
  69. callType = cursor1.getString(type);
  70. callDate = cursor1.getString(date);
  71.  
  72. callDateTime = new Date(Long.valueOf(callDate));
  73.  
  74. callDuration = cursor1.getString(duration);
  75.  
  76. // the string cType will give us text of either outgoing, incoming or missed
  77. String cType = null;
  78.  
  79.  
  80. int cTypeCode = Integer.parseInt(callType);
  81.  
  82. switch(cTypeCode)
  83. {
  84. case CallLog.Calls.OUTGOING_TYPE:
  85. cType = "OUTGOING";
  86. break;
  87.  
  88. case CallLog.Calls.INCOMING_TYPE:
  89. cType= "INCOMING";
  90. break;
  91.  
  92. case CallLog.Calls.MISSED_TYPE:
  93. cType = "MISSED";
  94. break;
  95. }
  96.  
  97. CallData calldata=new CallData(cType, phoneNumber, callDateTime, callDuration);
  98. list.add(calldata);
  99. }
  100.  
  101. cursor1.close();
  102. }
  103. }
  104.  
  105. int type = cursor1.getColumnIndex( CallLog.Calls.TYPE);
  106.  
  107. String type = cursor1.getString(cursor1.getColumnIndex(CallLog.Calls.TYPE));
  108.  
  109. switch (Integer.parseInt(type))
  110.  
  111. package com.example.chris.sunil_gupta;
  112.  
  113. import java.util.ArrayList;
  114. import java.util.Date;
  115. import java.util.List;
  116.  
  117. import android.app.Activity;
  118. import android.content.Context;
  119. import android.database.Cursor;
  120. import android.os.Bundle;
  121. import android.provider.CallLog;
  122. import android.widget.ListView;
  123.  
  124. public class MainActivity extends Activity {
  125.  
  126.  
  127.  
  128. private List <CallData>list = new ArrayList<CallData>();
  129. private Context context=null;
  130. @Override
  131. protected void onCreate(Bundle savedInstanceState) {
  132.  
  133. ListView listview;
  134.  
  135. super.onCreate(savedInstanceState);
  136. setContentView(R.layout.activity_main);
  137.  
  138. context=this;
  139.  
  140. listview=(ListView)findViewById(R.id.ListView_CallData);
  141.  
  142. getCallDetails();
  143. CustomAdapter adapter = new CustomAdapter(MainActivity.this, list);
  144. listview.setAdapter(adapter);
  145. }
  146.  
  147. public void getCallDetails()
  148. {
  149.  
  150.  
  151. // cursor1 gets all the items in the calllog and arranges them from newest call down
  152. Cursor cursor1 = getContentResolver().query(
  153. CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DATE + " DESC");
  154.  
  155. //looks like all the cell values in the calllog database are integers
  156. int number = cursor1.getColumnIndex( CallLog.Calls.NUMBER );
  157. // int type = cursor1.getColumnIndex( CallLog.Calls.TYPE );
  158. String type = cursor1.getString(cursor1.getColumnIndex(CallLog.Calls.TYPE));
  159. int date = cursor1.getColumnIndex( CallLog.Calls.DATE);
  160. int duration = cursor1.getColumnIndex(CallLog.Calls.DURATION);
  161.  
  162.  
  163. //declare some new variables here; we're going to convert the integers into these
  164.  
  165. String phoneNumber;
  166. String callDate;
  167. String callDuration;
  168. Date callDateTime;
  169.  
  170. //go through all the rows in the db and convert the values to strings or whatever
  171. while (cursor1.moveToNext())
  172. {
  173.  
  174. phoneNumber = cursor1.getString(number);
  175.  
  176. callDate = cursor1.getString(date);
  177.  
  178. callDateTime = new Date(Long.valueOf(callDate));
  179.  
  180. callDuration = cursor1.getString(duration);
  181.  
  182. // the string cType will give us text of either outgoing, incoming or missed
  183. String cType = null;
  184.  
  185. switch (Integer.parseInt(type))
  186. {
  187. case CallLog.Calls.OUTGOING_TYPE:
  188. cType = "OUTGOING";
  189. break;
  190.  
  191. case CallLog.Calls.INCOMING_TYPE:
  192. cType= "INCOMING";
  193. break;
  194.  
  195. case CallLog.Calls.MISSED_TYPE:
  196. cType = "MISSED";
  197. break;
  198. }
  199.  
  200. CallData calldata=new CallData(cType, phoneNumber, callDateTime, callDuration);
  201. list.add(calldata);
  202. }
  203.  
  204. cursor1.close();
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement