我正在尝试将“收藏夹”插入到我的数据库中,但是我在日志中遇到了这个我无法理解的错误。有人可以帮我解决这个问题吗?
以下是我在活动中调用的代码:
private static final String DATABASE_CREATE_FAVORITES = "create table "
+ TABLE_FAVORITES + "(" + CATEGORY + " text, " + TITLE_EN
+ " text, " + TITLE_FR + " text, " + TITLE_AR + " text,"
+ DESCRIPTION_EN + "text," + DESCRIPTION_FR + "text,"
+ DESCRIPTION_AR + "text," + DESCRIPTION_PH + "text, PRIMARY KEY ("
+ CATEGORY + ", " + TITLE_EN + ") );";
public long addFavorite(MyObject object) {
ContentValues values = new ContentValues();
values.put(CATEGORY, object.getCategory());
values.put(TITLE_EN, object.getTitleEn());
values.put(TITLE_FR, object.getTitleFr());
values.put(TITLE_AR, object.getTitleAr());
values.put(DESCRIPTION_EN, object.getDescriptionEn());
values.put(DESCRIPTION_FR, object.getDescriptionFr());
values.put(DESCRIPTION_AR, object.getDescriptionAr());
values.put(DESCRIPTION_PH, object.getDescriptionPh());
// Inserting Row
return database.insert(TABLE_FAVORITES, null, values);
}
这就是我在LogCat中得到的:
06-01 15:12:10.745: E/SQLiteDatabase(6766): Error inserting titleFR=1 - Lorsqu'on se réveille category=Home & Family DESCRIPTION_PH=Lâ ilâha illâ l-lâhu wahdahu lâ sharîka lahu, lahu-l-mulku wa lahu lhamdu, wa huwa calâ kulli shay’in qadîr. Subhâna l-lâhi, wa-l-hamdu li-l-lâhi, wa lâ ilâha illa l-lâhu, wa l-lâhu akbaru, wa lâ hawla wa lâ quwwata illa bi-l-lâhi-l-caliyyi-l-cazîm. Rabbi ghfir lî DESCRIPTION_AR=يَا أَيُّهَا الَّذِينَ آمَنُوا اذْكُرُوا اللهَ ذِكْرًا كَثِيراً DESCRIPTION_EN=O you who believe, remember Allah with much rememberance titleAR=1 - أذكار الاستيقاظ من النوم DESCRIPTION_FR=O vous qui croyez ! Evoquez Allah d’une façon abondante titleEN=1 - When waking up
06-01 15:12:10.745: E/SQLiteDatabase(6766): android.database.sqlite.SQLiteException: table favorites has no column named DESCRIPTION_PH: , while compiling: INSERT INTO favorites(titleFR,category,DESCRIPTION_PH,DESCRIPTION_AR,DESCRIPTION_EN,titleAR,DESCRIPTION_FR,titleEN) VALUES (?,?,?,?,?,?,?,?)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:260)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:112)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1718)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1591)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at com.quanticapps.hisnalmuslim.functions.DatabaseHelper.addFavorite(DatabaseHelper.java:103)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at com.quanticapps.hisnalmuslim.Details$4.onClick(Details.java:222)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.view.View.performClick(View.java:3534)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.view.View$PerformClick.run(View.java:14263)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.os.Handler.handleCallback(Handler.java:605)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.os.Handler.dispatchMessage(Handler.java:92)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.os.Looper.loop(Looper.java:137)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at android.app.ActivityThread.main(ActivityThread.java:4441)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at java.lang.reflect.Method.invokeNative(Native Method)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at java.lang.reflect.Method.invoke(Method.java:511)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-01 15:12:10.745: E/SQLiteDatabase(6766): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
您的表创建错误,并且根本没有创建表。:
+ DESCRIPTION_EN + "text," + DESCRIPTION_FR + "text,"
+ DESCRIPTION_AR + "text," + DESCRIPTION_PH + "text,,PRIMARY KEY ("
虽然你应该写:
+ DESCRIPTION_EN + " text," + DESCRIPTION_FR + " text,"
+ DESCRIPTION_AR + " text," + DESCRIPTION_PH + " text, PRIMARY KEY ("
注意字段名称和字段类型之间的空格。