2011-06-03 78 views
0

如何檢查,如果某個值,請在表中的列或不我用這樣的方式,但應用程序崩潰時的值不在表的值檢查查詢存在

Cursor r = db.query(DATABASE_TABLE3, 
        new String[] { "_id", "point_name", "No_of_visits" }, 
        "point_langtitude" + "=" + lang + " and " + "point_latitude" 
        + "=" + lat, 
        null, 
        null, 
        null, 
        null); 

if(r == null) 
{ 
    return true; 
} 
else 
{ 
    r.moveToFirst(); 
    ContentValues args = new ContentValues(); 
    args.put("No_of_visits", 7); 
    boolean d = db.update(DATABASE_TABLE3, 
         args, 
         "_id" + "=" + r.getInt(0), 
         null) > 0; 
    return false; 
} 
+0

你能後的logcat的輸出之前使用調試器吧。 – Flo 2011-06-03 11:31:40

+0

06-03 11:43:27.820:錯誤/數據庫(490):錯誤插入points_counter = 1 point_langtitude = -10084093 _id = 26 point_latitude = 37422005 06-03 11:43:27.820:錯誤/數據庫(490):android .database.sqlite.SQLiteConstraintException:錯誤代碼19:約束失敗 – jamil 2011-06-03 11:44:59

+0

請任何幫助我需要這個在我的畢業項目 – jamil 2011-06-03 11:54:35

回答

1
if(r != null && r.moveToFirst()) { 
    // Update 
    r.close(); 
} else { 
    // Do not call r.close() here because r is null 
} 
+0

謝謝,你解決了它,但爲什麼我不能使用我使用的方式 – jamil 2011-06-03 12:44:27

+0

我更新了awnser,問題在你的代碼是你在r爲null時調用r.close()。 – 2011-06-03 12:45:08

+0

好吧,但即使當我刪除r.close問題仍然會出現 – jamil 2011-06-03 12:48:18

1

仔細一看:

if(r == null) 
{ 
    // r is null 
    r.close(); // what now ... ? 
    return true; 
} 

和提問:)