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);
我不知道我做錯了,他會喜歡任何幫助的感謝。
您的表格是如何定義的?特別是 - 它有什麼限制? – ruakh