我有一段基本上同步在线数据库之间的数据的代码。然而,我得到一个特定的代码行(map.put("id", obj.get(mydb.WEB_ID).toString());
)的错误,其中一个整数值从android sqlite数据库中获得并提交给在线数据库。全COSE是显示如下:Android HashMap问题
public void updateSQLite(String response){
ArrayList<HashMap<String, String>> syncL;
syncL = new ArrayList<HashMap<String, String>>();
// Create GSON object
Gson gson = new GsonBuilder().create();
try {
// Extract JSON array from the response
JSONArray arr = new JSONArray(response);
System.out.println(arr.length());
// If no of array elements is not zero
if(arr.length() != 0){
// Loop through each array element, get JSON object which has userid and username
for (int i = 0; i < arr.length(); i++) {
// Get JSON object
JSONObject obj = (JSONObject) arr.get(i);
System.out.println(obj.get("web_id"));
System.out.println(obj.get("phone_id"));
System.out.println(obj.get("msg_id"));
mydb.updateWebSync(obj.get(obj.get("phone_id").toString(), obj.get("msg_id").toString(), obj.get("web_id").toString());
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", obj.get(mydb.WEB_ID).toString());
map.put("p_id", obj.get(mydb.COLUMN_ID).toString());
map.put("s", "1");
syncL.add(map);
}
updateMySQLSyncSts(gson.toJson(syncL), "syncsts");
Toast.makeText(getApplicationContext(), "Download Messages success!", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Download Messages error!", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
在我的Android SQLite数据库中,mydb.WEB_ID
的值存储为一个整数。任何援助表示赞赏。
什么样的错误?编译时间或运行时间?如果使用'String.valueOf(obj.get(“web_id”))''而不是'obj.get(mydb.WEB_ID).toString()'会发生什么? – Blackbelt
错误仍然相同。至于它是编译时还是运行时错误,我真的不知道其中的差别,但错误开始像'13704-13704 /? W/System.err:' – Biko