我正在尝试从带有android的应用程序中的表单中获取答案。活动一切都很好,但问题是我无法将答案插入数据库中。
这是我在logcat中得到的错误:
07-31 02:34:44.092: E/Database(398): Error inserting REP3=oui REP4=non REP1=oui REP2=oui LONGITUDE=0.0 ZONE=rabat REP5=oui LATITUDE=0.0
07-31 02:34:44.092: E/Database(398): android.database.sqlite.SQLiteException: table Appreciation has no column named REP4: , while compiling: INSERT INTO Appreciation(REP3, REP4, REP1, REP2, LONGITUDE, ZONE, REP5, LATITUDE) VALUES(?, ?, ?, ?, ?, ?, ?, ?);
07-31 02:34:44.092: E/Database(398): at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
07-31 02:34:44.092: E/Database(398): at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
07-31 02:34:44.092: E/Database(398): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
07-31 02:34:44.092: E/Database(398): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
07-31 02:34:44.092: E/Database(398): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1026)
07-31 02:34:44.092: E/Database(398): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1412)
07-31 02:34:44.092: E/Database(398): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1285)
07-31 02:34:44.092: E/Database(398): at com.stage.sondage.SurveyAdapter.insertAppreciation(SurveyAdapter.java:75)
07-31 02:34:44.092: E/Database(398): at com.stage.sondage.Questionnaire$1.onClick(Questionnaire.java:64)
07-31 02:34:44.092: E/Database(398): at android.view.View.performClick(View.java:2364)
07-31 02:34:44.092: E/Database(398): at android.view.View.onTouchEvent(View.java:4179)
07-31 02:34:44.092: E/Database(398): at android.widget.TextView.onTouchEvent(TextView.java:6540)
07-31 02:34:44.092: E/Database(398): at android.view.View.dispatchTouchEvent(View.java:3709)
07-31 02:34:44.092: E/Database(398): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-31 02:34:44.092: E/Database(398): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-31 02:34:44.092: E/Database(398): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-31 02:34:44.092: E/Database(398): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-31 02:34:44.092: E/Database(398): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-31 02:34:44.092: E/Database(398): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
07-31 02:34:44.092: E/Database(398): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
07-31 02:34:44.092: E/Database(398): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
07-31 02:34:44.092: E/Database(398): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
07-31 02:34:44.092: E/Database(398): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
07-31 02:34:44.092: E/Database(398): at android.os.Handler.dispatchMessage(Handler.java:99)
07-31 02:34:44.092: E/Database(398): at android.os.Looper.loop(Looper.java:123)
07-31 02:34:44.092: E/Database(398): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-31 02:34:44.092: E/Database(398): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 02:34:44.092: E/Database(398): at java.lang.reflect.Method.invoke(Method.java:521)
07-31 02:34:44.092: E/Database(398): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-31 02:34:44.092: E/Database(398): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-31 02:34:44.092: E/Database(398): at dalvik.system.NativeStart.main(Native Method)
它说错误在:
7-31 02:34:44.092: E/Database(398): android.database.sqlite.SQLiteException: table Appreciation has no column named REP4: , while compiling: INSERT INTO Appreciation(REP3, REP4, REP1, REP2, LONGITUDE, ZONE, REP5, LATITUDE) VALUES(?, ?, ?, ?, ?, ?, ?, ?);
以及
07-31 02:34:44.092: E/Database(398): at com.stage.sondage.SurveyAdapter.insertAppreciation(SurveyAdapter.java:75)
07-31 02:34:44.092: E/Database(398): at com.stage.sondage.Questionnaire$1.onClick(Questionnaire.java:64)
是
survey.insertAppreciation(appreciation); //in Questionnaire.java
and
return bdd.insert(APPRECIATION_TABLE_NAME, null, values);// in survey adapter
它表示COLUMN REP4不存在于表中欣赏但是我确保这个COLUMN存在,同时声明类Appreciation扩展OpenHelper的类以及我在表中插入信息的方法
谢谢你的帮助
答案 0 :(得分:1)
在REP4的列名之后和TEXT NOT NULL
之前,您缺少一个空格:
您的代码是:
private static final String REQUETE_CREATION_BDD = "CREATE TABLE "+ APPRECIATION_TABLE_NAME + " (" + COLUMN_IDAPPRECIATION
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_ZONE
+ " TEXT NOT NULL, " +COLUMN_LATITUDE
+ " DOUBLE NOT NULL, " +COLUMN_LONGITUDE
+ " DOUBLE NOT NULL, " + COLUMN_REP1 + " TEXT NOT NULL, "
+ COLUMN_REP2 + " TEXT NOT NULL,"+COLUMN_REP3 + " TEXT NOT NULL,"
+COLUMN_REP4+"TEXT NOT NULL,"+COLUMN_REP5 +" TEXT NOT NULL);";
它应该是:
private static final String REQUETE_CREATION_BDD = "CREATE TABLE "+ APPRECIATION_TABLE_NAME + " (" + COLUMN_IDAPPRECIATION
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_ZONE
+ " TEXT NOT NULL, " +COLUMN_LATITUDE
+ " DOUBLE NOT NULL, " +COLUMN_LONGITUDE
+ " DOUBLE NOT NULL, " + COLUMN_REP1 + " TEXT NOT NULL, "
+ COLUMN_REP2 + " TEXT NOT NULL,"+COLUMN_REP3 + " TEXT NOT NULL,"
+COLUMN_REP4+" TEXT NOT NULL,"+COLUMN_REP5 +" TEXT NOT NULL);";