我有一个预算程序,它使用多个表来存储信息。当我尝试一次向多个表添加信息时,我最终只让第一个表接收任何信息。这是我使用的代码:
public SQLiteDatabase createBudget(String bname, String bpay, String bamount,
String bmemo) {
// TODO Auto-generated method stub
ContentValues t1 = new ContentValues();
ContentValues t2 = new ContentValues();
ContentValues t4 = new ContentValues();
t1.put(KEY_NAME, bname);
t1.put(KEY_PAYDAY,bpay);
t2.put(KEY_AMOUNT, bamount);
t4.put(KEY_MEMO, bmemo);
ourDatabase.insert(DATABASE_TABLE1, null, t1);
ourDatabase.insert(DATABASE_TABLE2, null, t2);
ourDatabase.insert(DATABASE_TABLE4, null, t4);
return ourDatabase;
}
我完全不知道该怎么做。我曾尝试在网上查找,但我发现的内容是针对单表数据库的。我将不胜感激任何帮助。这是 LogCat 内容:
11-13 10:14:33.935: E/SQLiteDatabase(662): Error inserting budget_amount=99
11-13 10:14:33.935: E/SQLiteDatabase(662): android.database.sqlite.SQLiteConstraintException: Budget_Items.edit_date may not be NULL (code 19)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:775)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
11-13 10:14:33.935: E/SQLiteDatabase(662): at budget.app.BudgetDB.createBudget(BudgetDB.java:161)
11-13 10:14:33.935: E/SQLiteDatabase(662): at budget.app.AddBudget$1.onClick(AddBudget.java:40)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.view.View.performClick(View.java:4084)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.view.View$PerformClick.run(View.java:16966)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.os.Handler.handleCallback(Handler.java:615)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.os.Handler.dispatchMessage(Handler.java:92)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.os.Looper.loop(Looper.java:137)
11-13 10:14:33.935: E/SQLiteDatabase(662): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-13 10:14:33.935: E/SQLiteDatabase(662): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 10:14:33.935: E/SQLiteDatabase(662): at java.lang.reflect.Method.invoke(Method.java:511)
11-13 10:14:33.935: E/SQLiteDatabase(662): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-13 10:14:33.935: E/SQLiteDatabase(662): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-13 10:14:33.935: E/SQLiteDatabase(662): at dalvik.system.NativeStart.main(Native Method)
11-13 10:14:33.955: E/SQLiteDatabase(662): Error inserting _memo=for pie
11-13 10:14:33.955: E/SQLiteDatabase(662): android.database.sqlite.SQLiteConstraintException: Budget_Memos.edit_date may not be NULL (code 19)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:775)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
11-13 10:14:33.955: E/SQLiteDatabase(662): at budget.app.BudgetDB.createBudget(BudgetDB.java:162)
11-13 10:14:33.955: E/SQLiteDatabase(662): at budget.app.AddBudget$1.onClick(AddBudget.java:40)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.view.View.performClick(View.java:4084)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.view.View$PerformClick.run(View.java:16966)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.os.Handler.handleCallback(Handler.java:615)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.os.Handler.dispatchMessage(Handler.java:92)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.os.Looper.loop(Looper.java:137)
11-13 10:14:33.955: E/SQLiteDatabase(662): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-13 10:14:33.955: E/SQLiteDatabase(662): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 10:14:33.955: E/SQLiteDatabase(662): at java.lang.reflect.Method.invoke(Method.java:511)
11-13 10:14:33.955: E/SQLiteDatabase(662): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-13 10:14:33.955: E/SQLiteDatabase(662): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-13 10:14:33.955: E/SQLiteDatabase(662): at dalvik.system.NativeStart.main(Native Method)