【发布时间】:2018-10-05 11:41:41
【问题描述】:
每当尝试获取 getSelectedCustomerPhone() 时,我都会随机遇到一个问题,然后会出现随机光标索引超出绑定异常。 这段代码有什么问题吗?我找不到错误。
private String getSelectedCustomerPhone() {
myCursor.moveToPosition(selectedCustPosition);
String phone =
myCursor.getString(myCursor.getColumnIndex("cust_phone"));
if (phone != null) return phone;
return "";
}
【问题讨论】:
-
selectedCustPosition可能不是有效的行索引。索引从零开始,因此大小为 11,有效索引为 0..10。