0

I dont know why this is happening but no table is created on my Redmi Note 7s when I execute the code but its working fine on GIONEE smartphone and also on virtual devices. I tried changing database version also but no output.

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);
    }
}

1 Answers1

0

Chances are that your device already has AttendanceDb11 version 1 but without the tables. Uninstall your app to get rid of the old database version.

Try to change database name

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

instead of

public static  final String dbname = "AttendanceDb11";

When you create database and table then error should be occurred. Please paste that error.