gpt4 book ai didi

android - SQLite-列未创建

转载 作者:行者123 更新时间:2023-12-03 18:14:10 25 4
gpt4 key购买 nike

我已经阅读了之前的文章,但都没有提供有效的解决方案(重新启动模拟器,逗号,间距调整)。

创建一个简单的SQLite数据库,但是每次运行它都会收到相同的错误;

05-12 04:06:17.541    2063-2063/com.disclosure_scots.disclosure_scots E/SQLiteLog﹕ (1) table login has no column named tel_no
05-12 04:06:17.542 2063-2063/com.disclosure_scots.disclosure_scots E/SQLiteDatabase﹕ Error inserting email=test@email.com name=test name tel_no=1231234123 created_at=2015-05-12 06:06:19 uid=55517c3b97a8b8.60336236
android.database.sqlite.SQLiteException: table login has no column named tel_no (code 1): , while compiling: INSERT INTO login(email,name,tel_no,created_at,uid) VALUES (?,?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
at com.disclosure_scots.disclosure_scots.SQLiteHandler.addUser(SQLiteHandler.java:85)
at com.disclosure_scots.disclosure_scots.RegisterActivity$2.onResponse(RegisterActivity.java:151)
at com.disclosure_scots.disclosure_scots.RegisterActivity$2.onResponse(RegisterActivity.java:128)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)


在我的代码中,我尝试使用不同的间距进行此操作无济于事;

// Login Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_EMAIL = "email";
private static final String KEY_UID = "uid";
private static final String KEY_CREATED_AT = "created_at";
private static final String KEY_TEL_NO = "tel_no";

public SQLiteHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_LOGIN + "("
+ KEY_ID + " INTEGER PRIMARY KEY, "
+ KEY_NAME + " TEXT, "
+ KEY_EMAIL + " TEXT UNIQUE, "
+ KEY_UID + " TEXT, "
+ KEY_CREATED_AT + " TEXT, "
+ KEY_TEL_NO + " TEXT " + ")";
db.execSQL(CREATE_LOGIN_TABLE);

Log.d(TAG, "Database tables created");
}

// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_LOGIN);

// Create tables again
onCreate(db);
}


我缺少明显的东西吗?

最佳答案

正确,尽管重新启动了模拟器,但每次我运行主应用程序时,仍然出现了我在另一个Android Studio窗口中使用相同数据库名称运行的第二个应用程序正在启动的情况。

感谢您的回答,很抱歉浪费您的时间。

关于android - SQLite-列未创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30181740/

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