我正在尝试查看按发件人号码分组的收件箱。为此,我首先从收件箱中找到所有消息到他们的号码,然后当他们点击特定项目时,他将看到他们之间的对话。但是得到一个错误。
这是我的代码:
public void initialize() {
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(Uri.parse("content://sms/inbox"),
null, null, null, null);
startManagingCursor(cursor);
int indexBody = cursor.getColumnIndex(SmsReceiver.BODY);
int indexAddr = cursor.getColumnIndex(SmsReceiver.ADDRESS);
int i = 0, flag = 0;
if (indexBody < 0 || !cursor.moveToFirst())
return;
smsList.clear();
do {
// int cursorPostion = cursor.getPosition();
String address;
String msgStr = cursor.getString(indexBody);
String senderNumber = cursor.getString(indexAddr);
String name = cursor.getString(cursor
.getColumnIndex(PhoneLookup.DISPLAY_NAME));
if (name != null) {
address = name;
} else {
address = senderNumber;
}
flag = 1;
for (int j = 0; j < addressUniqueness.length; j++) {
if (addressUniqueness[j].contentEquals(address)) {
flag = 0;
break;
}
}
if (flag == 1) {
addressUniqueness[i] = address;
i++;
String str = "Sender: " + address + "\n";
smsList.add(str);
}
// TODO Auto-generated catch block
} while (cursor.moveToNext());
// cursor.moveToNext();
// }
ListView smsListView = (ListView) findViewById(R.id.SMSList);
smsListView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, smsList));
smsListView.setOnItemClickListener(this);
}
收到此错误:
01-08 22:09:03.034: E/AndroidRuntime(650): FATAL EXCEPTION: main
01-08 22:09:03.034: E/AndroidRuntime(650): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.InboxList}: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
01-08 22:09:03.034: E/AndroidRuntime(650): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-08 22:09:03.034: E/AndroidRuntime(650): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-08 22:09:03.034: E/AndroidRuntime(650): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-08 22:09:03.034: E/AndroidRuntime(650): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-08 22:09:03.034: E/AndroidRuntime(650): at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 22:09:03.034: E/AndroidRuntime(650): at android.os.Looper.loop(Looper.java:123)
01-08 22:09:03.034: E/AndroidRuntime(650): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-08 22:09:03.034: E/AndroidRuntime(650): at java.lang.reflect.Method.invokeNative(Native Method)
01-08 22:09:03.034: E/AndroidRuntime(650): at java.lang.reflect.Method.invoke(Method.java:507)
01-08 22:09:03.034: E/AndroidRuntime(650): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-08 22:09:03.034: E/AndroidRuntime(650): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-08 22:09:03.034: E/AndroidRuntime(650): at dalvik.system.NativeStart.main(Native Method)
01-08 22:09:03.034: E/AndroidRuntime(650): Caused by: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
01-08 22:09:03.034: E/AndroidRuntime(650): at android.database.CursorWindow.getString_native(Native Method)
01-08 22:09:03.034: E/AndroidRuntime(650): at android.database.CursorWindow.getString(CursorWindow.java:329)
01-08 22:09:03.034: E/AndroidRuntime(650): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
01-08 22:09:03.034: E/AndroidRuntime(650): at android.database.CursorWrapper.getString(CursorWrapper.java:135)
01-08 22:09:03.034: E/AndroidRuntime(650): at com.InboxList.initialize(InboxList.java:153)
01-08 22:09:03.034: E/AndroidRuntime(650): at com.InboxList.onCreate(InboxList.java:74)
01-08 22:09:03.034: E/AndroidRuntime(650): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-08 22:09:03.034: E/AndroidRuntime(650): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-08 22:09:03.034: E/AndroidRuntime(650): ... 11 more