Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name expected in kotlin

I am getting an error and im not sure why, I've tried a few different solutions ive found online and nothing has worked.

@Database(entities = {Tea.class}, version = 1, exportSchema = false)

the error im getting is that "Name expected" for after {Tea/class}

package com.google.developers.teacup.data

import android.content.Context
import androidx.room.Database
import androidx.room.Entity
import androidx.room.RoomDatabase
@Entity
@Database(entities = {Tea.class}, version = 1, exportSchema = 
false)
abstract class TeaDatabase: RoomDatabase() {

    abstract fun teaDao(): TeaDao

    companion object {

    @Volatile
    private var instance: TeaDatabase? = null

    /**
     * Returns an instance of Room Database
     *
     * @param context application context
     * @return The singleton TeaDatabase
     */
    fun getInstance(context: Context): TeaDatabase {

    return(instance!!)}
    }
}
like image 771
Dnysus Avatar asked Nov 24 '25 23:11

Dnysus


1 Answers

As per Kotlin syntax, you need to replace Tea.class with Tea::class

@Database(entities = {Tea::class}, version = 1, exportSchema = false)

Remove @Entity from your TeaDatabase class and add it to Tea.class.

Hope it should solve your problem.

like image 71
Shailendra Madda Avatar answered Nov 26 '25 12:11

Shailendra Madda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!