不好意思,三次提问都是同一个问题,因为不懂得提问的方式(以后提问会慎重的),以及修改不了内容,所以只好新开了一个提问
以下是源码,依赖包已经检查过了,都导入了
错误信息如下:
错误: <匿名com.jetapps.vpns.master.app.data.room.ServerInfoDB_Impl$1>中的onCreate(SupportSQLiteDatabase)无法覆盖Delegate中的onCreate(SupportSQLiteDatabase)
protected void onCreate(SupportSQLiteDatabase _db) {
^
正在尝试分配更低的访问权限; 以前为public
原本错误信息是乱码的,添加UTF-8,弄好之后就是上面这个样子了,原本的如下:
����: <����com.xxx.room.database.ServerDatabase_Impl$1>�е�onCreate(SupportSQLiteDatabase)������Delegate�е�onCreate(SupportSQLiteDatabase)
protected void onCreate(SupportSQLiteDatabase _db) {
���ڳ��Է�����͵ķ���Ȩ��; ��ǰΪpublic
import android.content.Context
import androidx.lifecycle.LiveData
import androidx.room.*
@Entity(tableName = "server_info_table")
data class ServerInfoEntity(
@PrimaryKey val cname: String,
val image: String?,
val timeDelay: Float,
val checkState: Boolean?
)
@Dao
interface ServerInfoDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertServerInfo(serverInfoEntity: ServerInfoEntity)
@Delete
fun deleteServerInfo(serverInfoEntity: ServerInfoEntity)
}
@Database(entities = [ServerInfoEntity::class], version = 1)
abstract class ServerInfoDB: RoomDatabase() {
abstract fun serverInfoDao(): ServerInfoDao
companion object{
@Volatile
private var instance: ServerInfoDB? = null
@Synchronized
fun getInstance(context: Context): ServerInfoDB =
instance ?: Room.databaseBuilder(context, ServerInfoDB::class.java,
"server_info_db"
).build()
.also { instance = it }
}
}
firebase - Android Room Porblem: protected void onCreate(SupportSQLiteDatabase _db) - Stack Overflow
可以试着降低依赖的版本来解决,