gpt4 book ai didi

android - 在表 sqlite 中找不到命名的列

转载 作者:行者123 更新时间:2023-11-30 03:25:20 25 4
gpt4 key购买 nike

假设我的代码是正确的,但即使它给出错误 column not found for _pay_mode :

洛卡特:

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

但仍然没有得到解决方案。!!!

最佳答案

我觉得

KEY_PAY_MODE + "TEXT"

pay_modeTEXT。空间不足?

此外,如果 CREATE TABLE 已经存在,是否根本不进行处理?为了以防万一,您是否明确尝试了 DROP TABLEDROP DATABASE

(注:我对Android平台一无所知,这些都是通用的SQL思路)

关于android - 在表 sqlite 中找不到命名的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18325104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com