在我的代碼,當光標爲null我遇到的CursorIndexOutOfBoundsException Index 0 requested, with a size of 0 in Android
CursorIndexOutOfBoundsException的Android
的例外,我怎樣才能解決這個問題?
public Cursor getCustAccount(long custRef){
openReadable();
Cursor cursor;
cursor = database.rawQuery(" SELECT CustAccountId AS _id,AccountNo as AccountNo,BankName as BankName,BranchName as BranchName FROM tblCustAccount WHERE CustRef =" + custRef , null);
if (cursor != null)
cursor.moveToFirst();
return cursor;
}
public ArrayList<String> getCustAccountString(long custRef) {
Cursor cursor = getCustAccount(custRef);
ArrayList<String> listAccount = new ArrayList<String>();
do {
listAccount.add(String.valueOf(cursor.getInt(1)));
} while(cursor.moveToNext());
return listAccount;
}
如果'cursor'用'null'等於那麼你的應用程序必須拿到'Exception' –
FYI:把你的問題的標題在搜索引擎,這樣就造成同許多職位都有正確的解決方案。 – laalto