【发布时间】:2015-10-07 10:52:40
【问题描述】:
我有一段代码基本上可以在在线数据库之间同步数据。但是,我在一个特定的代码行 (map.put("id", obj.get(mydb.WEB_ID).toString());) 上遇到错误,其中一个整数值是从 android sqlite 数据库获取并提交到在线数据库的。完整的cos如下图:
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()会发生什么? -
报错还是一样。关于它是编译时错误还是运行时错误,我真的不知道区别,但错误开始于
13704-13704/? W/System.err:
标签: android hashmap android-sqlite