我有一个基本数据库,它将字符串调用到数据库中(很好)。每当我单击按钮将字符串保存到数据库中时,我的日志cat中会出现错误,说它没有写入数据库。应用程序继续运行但数据库内没有信息显示。
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 :(得分:4)
堆栈中最顶层的行说:
12-02 16:39:03.551: E/Database(20828): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
您是否违反了约束条件:
你可以发布有问题的表的create sql吗?
答案 1 :(得分:1)
我必须卸载我的应用程序,然后重新安装它以进行更改以采取措施。