我的代码是正确的假设,但即使它为_pay_mode找不到错误coloumn:
LOGCAT:
08-20 05:22:05.398: D/Reading:(17403): Reading all contacts..
08-20 05:22:05.539: D/income(17403): table created with price type date description pay_mode
08-20 05:22:35.164: E/Database(17403): Error inserting income
08-20 05:22:35.164: E/Database(17403): android.database.sqlite.SQLiteException: table income has no column named pay_mode: , while compiling: INSERT INTO income(pay_mode, price, date, type, description) VALUES(?, ?, ?, ?, ?);
08-20 05:22:35.164: E/Database(17403): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
08-20 05:22:35.164: E/Database(17403): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
08-20 05:22:35.164: E/Database(17403): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
08-20 05:22:35.164: E/Database(17403): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
08-20 05:22:35.164: E/Database(17403): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
08-20 05:22:35.164: E/Database(17403): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1151)
08-20 05:22:35.164: E/Database(17403): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1571)
08-20 05:22:35.164: E/Database(17403): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1428)
08-20 05:22:35.164: E/Database(17403): at com.parth.targetthebudget.DatabaseHandler.addContact(DatabaseHandler.java:81)
08-20 05:22:35.164: E/Database(17403): at com.parth.targetthebudget.Add_Income.onClick(Add_Income.java:58)
08-20 05:22:35.164: E/Database(17403): at android.view.View.performClick(View.java:2485)
08-20 05:22:35.164: E/Database(17403): at android.view.View$PerformClick.run(View.java:9080)
08-20 05:22:35.164: E/Database(17403): at android.os.Handler.handleCallback(Handler.java:587)
08-20 05:22:35.164: E/Database(17403): at android.os.Handler.dispatchMessage(Handler.java:92)
08-20 05:22:35.164: E/Database(17403): at android.os.Looper.loop(Looper.java:130)
08-20 05:22:35.164: E/Database(17403): at android.app.ActivityThread.main(ActivityThread.java:3687)
08-20 05:22:35.164: E/Database(17403): at java.lang.reflect.Method.invokeNative(Native Method)
08-20 05:22:35.164: E/Database(17403): at java.lang.reflect.Method.invoke(Method.java:507)
08-20 05:22:35.164: E/Database(17403): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-20 05:22:35.164: E/Database(17403): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-20 05:22:35.164: E/Database(17403): at dalvik.system.NativeStart.main(Native Method)
OnCreate和OnUpgrade方法:
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_INCOME_TABLE = "CREATE TABLE if not exists " + TABLE_INCOME + "("
+ KEY_PRICE + "REAL,"
+ KEY_TYPE + "TEXT,"
+ KEY_DATE + "TEXT,"
+ KEY_DESCRIPTION + "TEXT,"
+ KEY_PAY_MODE + "TEXT"
+")";
db.execSQL(CREATE_INCOME_TABLE);
Log.d(TABLE_INCOME, "table created with "+ KEY_PRICE +" "+ KEY_TYPE +" "
+ KEY_DATE +" " + KEY_DESCRIPTION +" " + KEY_PAY_MODE);
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_INCOME);
// Create tables again
onCreate(db);
}
在研究了这些答案后,我尝试更改数据库版或删除我的应用,然后重新安装:
Android SQLite Column Not Found Error When Executing Raw Query
SQLite android column not found
但仍然没有得到解决方案。!!!
答案 0 :(得分:1)
在我看来
KEY_PAY_MODE + "TEXT"
是pay_modeTEXT
。空间不足?
另外,如果CREATE TABLE
已经存在,那么它是否可以完全处理?您是否明确尝试DROP TABLE
或DROP DATABASE
?
(注意:我对Android平台一无所知,所有这些都是一般的SQL想法)