在我的 SQlite 数据库中,数据没有创建 (Kotlin)

In my SQliteDatabase date is not createing (Kotlin)

我在 android studio 中有一个 SqlitieDatebase,由于某种原因,数据库没有创建。如果有人能帮我解决这个问题,我真的很高兴。

我没有收到关于数据库的所有错误。

感谢您的帮助

这是我刚刚启动数据库的代码

class MainActivity : AppCompatActivity() {
    val eventdata = null
    val dbHelper = EventDatabasek(this)
    val STORAGE_LOCAL =101

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        applicationContext

        checkPer(WRITE_EXTERNAL_STORAGE, "storage", STORAGE_LOCAL)
        val eventDatabasek = EventDatabasek(this)





        val calen = findViewById<Button>(R.id.btnCal)
        val curr = findViewById<Button>(R.id.btnCurrApp)
        val newpla = findViewById<Button>(R.id.btnSetNew)
        val exitapp = findViewById<Button>(R.id.btnExit)

        calen.setOnClickListener{

            val intent = Intent(this, Cal::class.java)
            startActivity(intent)
        }
        curr.setOnClickListener {
            val intent = Intent( this, CurrentSch:: class.java)
            startActivity(intent)
        }
        newpla.setOnClickListener{

            val intent = Intent(this, NewPlan::class.java)
            startActivity(intent)
        }

        exitapp.setOnClickListener {
            finish()
            exitProcess(0)
        }
    }

这是我创建的数据库。

class EventDatabasek(context: Context) :

    SQLiteOpenHelper(context, DATABASE_NAME,  null, DATABASE_VERSION){


    companion object {
        private  const val DATABASE_VERSION =1
        private  const val DATABASE_NAME ="EventDataBase"
        private  const val TABLE_CONTACTS = "EventTable"

        private const val KEY_ID = "_id"
        private const val KEY_DATE = "date"
        private const val KEY_TIME = "time"
        private const val KEY_REPEAT = "repeat"
        private const val KEY_EMAIL = "email"
        private const val KEY_NOTES = "notes"
    }
    override fun onCreate(db: SQLiteDatabase?){

        val CREATE_CONTACTS_TABLE = (" CREATE TABLE " + TABLE_CONTACTS + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT , " + KEY_DATE + " TEXT NOT NULL ," + KEY_TIME + "TEXT NOT NULL ," + KEY_REPEAT
                + " INTEGER ," + KEY_EMAIL + " TEXT NOT NULL , " + KEY_NOTES + " TEXT NOT NULL , " +")")

        db?.execSQL(CREATE_CONTACTS_TABLE)

    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        db!!.execSQL("DROP TABLE IF EXISTS $TABLE_CONTACTS")

        onCreate(db)
    }

    fun addEvent(evt: EventModelk): Long {
        val db = this.writableDatabase

        val contentValues = ContentValues()

        contentValues.put(KEY_DATE, evt.dDate)
        contentValues.put(KEY_TIME, evt.tTime)
        contentValues.put(KEY_REPEAT, evt.repeat)
        contentValues.put(KEY_EMAIL, evt.eEmail)
        contentValues.put(KEY_NOTES, evt.nNotes)

        val success = db.insert(TABLE_CONTACTS, null, contentValues)


        db.close()

        return success
    }

    fun veiwEvent (): ArrayList<EventModelk> {
        val evtlist: ArrayList<EventModelk> = ArrayList<EventModelk>()
        val  selectQueue = "SELECT * FROM $TABLE_CONTACTS"

        val db = this?.readableDatabase
        var cursor: Cursor?

        try {
            cursor = db.rawQuery(selectQueue, null)

        }catch (e: SQLException){

            db.execSQL(selectQueue)
            return  ArrayList()

        }
        var id:Int
        var date: String
        var time: String
        var repeat: Int
        var email: String
        var note: String

        if (cursor.moveToFirst()){
            do {
                id = cursor.getInt(cursor.getColumnIndex(KEY_ID))
                date = cursor.getString(cursor.getColumnIndex(KEY_DATE))
                time = cursor.getString(cursor.getColumnIndex(KEY_TIME))
                repeat = cursor.getInt(cursor.getColumnIndex(KEY_REPEAT))
                email = cursor.getString(cursor.getColumnIndex(KEY_EMAIL))
                note = cursor.getString(cursor.getColumnIndex(KEY_NOTES))

                val evt = EventModelk(id = id, dDate = date, tTime = time, repeat = repeat, eEmail = email, nNotes = note)
                evtlist.add(evt)
            }while (cursor.moveToNext())

        }
        return evtlist
    }

    fun updateEventdata(evt: EventModelk): Int {
        val db = this.writableDatabase
        val contentValues = ContentValues()

        contentValues.put(KEY_DATE, evt.dDate)
        contentValues.put(KEY_TIME, evt.tTime)
        contentValues.put(KEY_REPEAT, evt.repeat)
        contentValues.put(KEY_EMAIL, evt.eEmail)
        contentValues.put(KEY_NOTES, evt.nNotes)

        val success = db.update(TABLE_CONTACTS, contentValues, KEY_ID + "=" + evt.id, null)


        db.close()

        return success
    }

    fun deleteEvent(evt: EventModelk): Int {
        val db = this.writableDatabase
        val contentValues = ContentValues()

        contentValues.put(KEY_ID, evt.id)

        val success = db.delete(TABLE_CONTACTS, KEY_ID + "=" +evt.id, null)

        db.close()

        return success
    }
}

这是我现在得到的错误

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
 Caused by: android.database.sqlite.SQLiteException: near ")": syntax error (code 1 SQLITE_ERROR): , while compiling: CREATE TABLE EventTable(_id INTEGER PRIMARY KEY AUTOINCREMENT , date TEXT NOT NULL ,timeTEXT NOT NULL ,repeat INTEGER ,email TEXT NOT NULL , notes TEXT NOT NULL , )
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:986)
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:593)
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:590)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:61)
    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:33)
    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1805)
    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1733)
    at com.example.scheduleit.EventDatabasek.onCreate(EventDatabasek.kt:32)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:412)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:317)
    at com.example.scheduleit.MainActivity.onCreate(MainActivity.kt:28)
    at android.app.Activity.performCreate(Activity.java:7802)
    at android.app.Activity.performCreate(Activity.java:7791)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)

将在您第一次调用 getReadableDatabase() or getWritableDatabase() in which case the onCreate() 方法时创建数据库 EventDatabasek class 将被调用。

您可以在这一行之后执行此操作:

val eventDatabasek = EventDatabasek(this)

通过调用:

eventDatabasek.getReadableDatabase()