我有一個小問題,讓在android.My我的數據庫SQLite數據庫元素的Android看起來是這樣的:如何從sqlite的數據 -
id/ serverName/objectId/objectOid/....//objectId is actually userId-which I need to compare
我是從服務器接收數據我需要檢查從服務器和本地用戶ID從database.I用戶的ID有這樣一段代碼:
public static Integer lUserIdByServerUserId(int serverUserId, String serverName){
return localUserIdByServerUserId(serverUserId, serverName);
}
private static Integer localUserIdByServerUserId(int serverUserId, String serverName){
DataBaseHelper dbHelper = new DataBaseHelper(context, "ops_sys_tpl.sqlite",null,1);
String query = "SELECT id FROM users WHERE objectId = "+serverUserId+" AND serverName = '"+serverName+"' LIMIT 1";
ArrayList<String> result = new ArrayList<String>();
cursor = dbHelper.executeSQLQuery(query);
cursor.moveToFirst();
while(!cursor.isAfterLast()) {
result.add(cursor.getString(cursor.getColumnIndex("objectId")));
cursor.moveToNext();
}
Log.i("result ","Result : "+result.toString());
Log.i("CURSOR ","Cursor Position : "+cursor.getPosition());
Integer uuid = Integer.parseInt(result.get(cursor.getColumnIndex("objectId")));
Log.w("localUSerByIdServerUserId","LocalUserByIdServerUserId result : "+uuid);
cursor.close();
return uuid;
}
我試圖檢查數據庫中的所有條目,如果有匹配返回它。我打電話給這樣的方法:
uuId = rpc.lUserIdByServerUserId(userId,newServerName);
,我在這行得到這個異常:Integer uuid = Integer.parseInt(result.get(cursor.getColumnIndex("objectId")));
09-20 16:55:47.647: WARN/System.err(31031): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
09-20 16:55:47.647: WARN/System.err(31031): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
09-20 16:55:47.647: WARN/System.err(31031): at java.util.ArrayList.get(ArrayList.java:311)
09-20 16:55:47.647: WARN/System.err(31031): at com.stampii.stampii.comm.rpc.RPCCommunicator.localUserIdByServerUserId(RPCCommunicator.java:1083)
09-20 16:55:47.647: WARN/System.err(31031): at com.stampii.stampii.comm.rpc.RPCCommunicator.lUserIdByServerUserId(RPCCommunicator.java:1066)
09-20 16:55:47.657: WARN/System.err(31031): at com.stampii.stampii.comm.rpc.InfoStartRPCPacket.executeBefore(InfoStartRPCPacket.java:176)
09-20 16:55:47.657: WARN/System.err(31031): at com.stampii.stampii.user.UserLogin$2$1.run(UserLogin.java:212)
09-20 16:55:47.657: WARN/System.err(31031): at java.lang.Thread.run(Thread.java:1102)
09-20 16:55:47.657: WARN/ERROR(31031): Error - java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
而實際上我在我的數據庫只有一個測試項,這與從服務器的用戶ID的回報。
任何想法,我的錯誤在哪裏以及如何解決?
什麼是(RPCCommunicator.java:1083)?請標記代碼行。 –
抱歉忘了提及它。我只是用正確的線更新我的問題:Integer uuid = Integer.parseInt(result.get(cursor.getColumnIndex(「objectId」))); –