2011-12-03 139 views
0

我有一個基本數據庫,它將字符串調用到數據庫中(應該是這樣)。每當我點擊按鈕將字符串保存到數據庫中時,我的日誌貓就會收到一條錯誤消息,說它沒有寫入數據庫。應用程序繼續運行,但數據庫內沒有顯示任何信息。插入到數據庫時出錯

logcat的

12-02 16:39:03.551: E/Database(20828): 0.0 
12-02 16:39:03.551: E/Database(20828): 0.0 
12-02 16:39:03.551: E/Database(20828): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed 
12-02 16:39:03.551: E/Database(20828): at android.database.sqlite.SQLiteStatement.native_execute(Native Method) 
12-02 16:39:03.551: E/Database(20828): at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:61) 
12-02 16:39:03.551: E/Database(20828): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1591) 
12-02 16:39:03.551: E/Database(20828): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1435) 
12-02 16:39:03.551: E/Database(20828): at http.www.hotapp.com.timeandlocation.db.Database.createEntryLat(Database.java:76) 
12-02 16:39:03.551: E/Database(20828): at http.www.hotapp.com.timeandlocation.TimeAndLocationActivity.onClick(TimeAndLocationActivity.java:131) 
12-02 16:39:03.551: E/Database(20828): at android.view.View.performClick(View.java:2485) 
12-02 16:39:03.551: E/Database(20828): at android.view.View$PerformClick.run(View.java:9089) 
12-02 16:39:03.551: E/Database(20828): at android.os.Handler.handleCallback(Handler.java:587) 
12-02 16:39:03.551: E/Database(20828): at android.os.Handler.dispatchMessage(Handler.java:92) 
12-02 16:39:03.551: E/Database(20828): at android.os.Looper.loop(Looper.java:123) 
12-02 16:39:03.551: E/Database(20828): at android.app.ActivityThread.main(ActivityThread.java:3806) 
12-02 16:39:03.551: E/Database(20828): at java.lang.reflect.Method.invokeNative(Native Method) 
12-02 16:39:03.551: E/Database(20828): at java.lang.reflect.Method.invoke(Method.java:507) 
12-02 16:39:03.551: E/Database(20828): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
12-02 16:39:03.551: E/Database(20828): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
12-02 16:39:03.551: E/Database(20828): at dalvik.system.NativeStart.main(Native Method) 

輸入方法

public long createEntryLat(String slat) { 
    // TODO Auto-generated method stub 

    ContentValues cv = new ContentValues(); 
    cv.put(KEY_LATITUDE, slat); 
    return ourdb.insert(DATABASE_TABLE, null, cv); 

} 

線73

return ourdb.insert(DATABASE_TABLE, null, cv); 

ONCLICK METHOUD

case R.id.button001: 

    lat = (EditText)findViewById(R.id.textLat); 
    String slat = lat.getText().toString(); 
     //String slon = lon.getText().toString(); 

     Database entries = new Database (this); 
     entries.open(); 

     entries.createEntryLat(slat); 
     entries.close(); 

     break; 

線131

Database entries = new Database (this); 

我不知道我做錯了,他會喜歡任何幫助的感謝。

+0

您的表格是如何定義的?特別是 - 它有什麼限制? – ruakh

回答

1

我不得不卸載我的應用程序,然後重新安裝它,以便我的更改採取行動。

4

堆棧中的最上一行說:

12-02 16:39:03.551: E/Database(20828): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed 

有沒有什麼違反了約束:

  • VARCHAR列是獨一無二的,你正試圖重新插入相同的值。
  • 其他一些約束像主鍵,外鍵等

你可以張貼在問題表中創建SQL?

相關問題