【问题标题】:Sqlite Table not creating on Xiaomi Note 7s but creating on other phones and virtual devices in Android StudioSqlite Table 不在小米 Note 7s 上创建,而是在 Android Studio 中的其他手机和虚拟设备上创建
【发布时间】:2020-08-05 14:08:10
【问题描述】:

我不知道为什么会发生这种情况,但是当我执行代码时,我的 Redmi Note 7s 上没有创建表,但它在 GIONEE 智能手机和虚拟设备上都可以正常工作。 我也尝试更改数据库版本,但没有输出。

package com.example.attendance;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class Databases extends SQLiteOpenHelper {

    public static  final String dbname = "AttendanceDb11";

    public Databases(@Nullable Context context) {
        super(context, dbname, null, 5);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS Student12 ( _id INTEGER PRIMARY KEY 
        AUTOINCREMENT, Name Text)";
        db.execSQL(CREATE_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("Drop table if exists Student12");
            onCreate(db);
    }
}

【问题讨论】:

  • public static final String dbname = "AttendanceDb11.db";
  • 请显示错误日志。

标签: android database sqlite android-studio redmi-device


【解决方案1】:

您的设备可能已经有 AttendanceDb11 版本 1 但没有表格。卸载您的应用以摆脱旧的数据库版本。

尝试更改数据库名称

public static  final String dbname = "AttendanceDb11.bd";

而不是

public static  final String dbname = "AttendanceDb11";

当您创建数据库和表时,应该会发生错误。请粘贴该错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多