這是我的表創建命令:SQLiteConstraintException
private static final String PINGPONG_CREATE = "create table " + TABLE_PINGPONG + "(" + COLUMN_ID_PINGPONG + " integer primary key autoincrement, " + COLUMN_CNAME +
" text not null, " + COLUMN_DATE + " text not null, " + " text not null, " + COLUMN_LEAD + " numeric, " + COLUMN_PLACE + " text not null, "
+ COLUMN_SET_ONE1 + " numeric, " + COLUMN_SET_ONE2 + " numeric, " + COLUMN_SET_TWO1 + " numeric, " + COLUMN_SET_TWO2 + " numeric, " + COLUMN_SET_THREE1
+ " numeric, " + COLUMN_SET_THREE2 + " numeric, " + COLUMN_SET_FOUR1 + " numeric, " + COLUMN_SET_FOUR2 + " numeric, " + COLUMN_SET_FIVE1 + " numeric, "
+ COLUMN_SET_FIVE2 + " numeric, " + COLUMN_SET_SIX1 + " numeric, " + COLUMN_SET_SIX2 + " numeric, " + COLUMN_SET_SEVEN1 + " numeric, " + COLUMN_SET_SEVEN2
+ " numeric, " + COLUMN_RESULT1 + " numeric, " + COLUMN_RESULT2 + " numeric);";
這是我的方法輸入 「PingPongeEntry」 到數據庫
public void createPingPongEntry(int lead, String challengeName, String date, String place, int set11, int set12, int set21, int set22,
int set31, int set32, int set41, int set42, int set51, int set52, int set61, int set62, int set71, int set72, int tot1, int tot2){
ContentValues values = new ContentValues();
values.put(CustomSQLiteHelper.COLUMN_LEAD, lead);
values.put(CustomSQLiteHelper.COLUMN_CNAME, challengeName);
values.put(CustomSQLiteHelper.COLUMN_DATE, date);
values.put(CustomSQLiteHelper.COLUMN_PLACE, place);
values.put(CustomSQLiteHelper.COLUMN_SET_ONE1, set11);
values.put(CustomSQLiteHelper.COLUMN_SET_ONE2, set12);
values.put(CustomSQLiteHelper.COLUMN_SET_TWO1, set21);
values.put(CustomSQLiteHelper.COLUMN_SET_TWO2, set22);
values.put(CustomSQLiteHelper.COLUMN_SET_THREE1, set31);
values.put(CustomSQLiteHelper.COLUMN_SET_THREE2, set32);
values.put(CustomSQLiteHelper.COLUMN_SET_FOUR1, set41);
values.put(CustomSQLiteHelper.COLUMN_SET_FOUR2, set42);
values.put(CustomSQLiteHelper.COLUMN_SET_FIVE1, set51);
values.put(CustomSQLiteHelper.COLUMN_SET_FIVE2, set52);
values.put(CustomSQLiteHelper.COLUMN_SET_SIX1, set61);
values.put(CustomSQLiteHelper.COLUMN_SET_SIX2, set62);
values.put(CustomSQLiteHelper.COLUMN_SET_SEVEN1, set71);
values.put(CustomSQLiteHelper.COLUMN_SET_SEVEN2, set72);
values.put(CustomSQLiteHelper.COLUMN_RESULT1, tot1);
values.put(CustomSQLiteHelper.COLUMN_RESULT2, tot2);
long insertID = database.insert(CustomSQLiteHelper.TABLE_PINGPONG, null, values);
Cursor cursor = database.query(CustomSQLiteHelper.TABLE_PINGPONG, allColumns3, CustomSQLiteHelper.COLUMN_ID_RUNNING + " = " + insertID, null, null, null, null);
cursor.moveToFirst();
cursor.close();
}
這就是allColums3-的String []
private String[] allColumns3 = {CustomSQLiteHelper.COLUMN_ID_PINGPONG, CustomSQLiteHelper.COLUMN_CNAME, CustomSQLiteHelper.COLUMN_DATE, CustomSQLiteHelper.COLUMN_PLACE, CustomSQLiteHelper.COLUMN_LEAD,
CustomSQLiteHelper.COLUMN_SET_ONE1,
CustomSQLiteHelper.COLUMN_SET_ONE2, CustomSQLiteHelper.COLUMN_SET_TWO1, CustomSQLiteHelper.COLUMN_SET_TWO2, CustomSQLiteHelper.COLUMN_SET_THREE1, CustomSQLiteHelper.COLUMN_SET_THREE2,
CustomSQLiteHelper.COLUMN_SET_FOUR1, CustomSQLiteHelper.COLUMN_SET_FOUR2, CustomSQLiteHelper.COLUMN_SET_FIVE1, CustomSQLiteHelper.COLUMN_SET_FIVE2, CustomSQLiteHelper.COLUMN_SET_SIX1,
CustomSQLiteHelper.COLUMN_SET_SIX2, CustomSQLiteHelper.COLUMN_SET_SEVEN1, CustomSQLiteHelper.COLUMN_SET_SEVEN2, CustomSQLiteHelper.COLUMN_RESULT1, CustomSQLiteHelper.COLUMN_RESULT2};
現在在線long insertID = database.insert(CustomSQLiteHelper.TABLE_PINGPONG, null, values);
我得到SQLiteConstraintException,我不知道爲什麼。它說:
09-29 19:55:13.151: E/Database(1609): Error inserting set51=0 set52=0 set41=3 set61=0 lead=0 set72=0 set71=0 set62=0 date=29-09-2012 result1=4 result2=0 name=pingpong set32=1 set31=3 set42=1 place=hier set22=1 set21=3 set12=1 set11=3
(我這裏也困惑,爲什麼沒有插入值的順序)
我讀過有關這個話題在這裏的一些問題,但所有給定recommandation有跟隨:主鍵是自動增量的,並且在此處我試圖插入記錄,數據庫爲空。
我有兩種方法可以通過類比插入FootBallEntrys
和Games
,並且一切正常。那麼爲什麼它不創建一個獨特的用戶界面?
我想你在這裏創建一個不能爲空的未命名的列:'+ COLUMN_DATE +「文本不爲空,」+「文本不爲空,'在插入時不提供值,所以失敗。 – zapl
@zapl雖然我很驚訝,桌子甚至編譯,但你應該發佈這個答案,你會得到我的贊成。 – Sam
它實際上是我監督的一段代碼,如果你把它作爲答案發布,當然我會接受它 –