我正在做一个获取通话记录的程序,但我遇到了一些问题。 我在这个程序运行时遇到了崩溃,崩溃是数字格式异常无效int 1415715471534。有人能解决这个问题吗?这是我的代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_satu);
Cursor mCursor = managedQuery(CallLog.Calls.CONTENT_URI, null, null, null, null);
int number = mCursor.getColumnIndex(CallLog.Calls.NUMBER);
int date = mCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = mCursor.getColumnIndex(CallLog.Calls.DURATION);
int type = mCursor.getColumnIndex(CallLog.Calls.TYPE);
StringBuilder sb = new StringBuilder();
while(mCursor.moveToNext()){
String phnNumber = mCursor.getString((int) number);
String callDuration = mCursor.getString(duration);
String callType = mCursor.getString(type);
String callDate = mCursor.getString(date);
Date d = new Date(callDate);
String callTypeStr = null;
int dircode = Integer.parseInt(callType);
switch (dircode){
case CallLog.Calls.OUTGOING_TYPE:
callTypeStr = "Outgoing";
break;
case CallLog.Calls.INCOMING_TYPE:
callTypeStr = "Incoming";
break;
case CallLog.Calls.MISSED_TYPE:
callTypeStr = "Missed";
break;
}
sb.append("Phone number" + phnNumber);
sb.append("Call Duration" + callDuration);
sb.append("Call type" + callTypeStr);
sb.append("Call date" + d);
sb.append("-------------------");
sb.append(System.getProperty("line.separator"));
mCursor.close();
}
TextView callDetails = (TextView) findViewById(R.id.callog);
callDetails.setText(sb.toString());
}
答案 0 :(得分:0)
我认为问题是int
可以容纳的最大值是2^31-1
。您的值1415715471534
不仅仅是这个。这就是你收到错误的原因。