Добрый день
Столкнулся с проблемой реализации Базы данных для приложения Андроид на Kotlin, наверняка вопрос простой, но так как я новичок самоучка, разобраться не получается, очень прошу Вас помочь мне
При запуске эмулятора возникает ошибка сборки билда: E:\Android\Sumrak\app\build\tmp\kapt3\stubs\debug\com\example\sumrak\DaoPlayerDb.java:9: error: Type of the parameter must be a class annotated with @Entity or a collection/array of it.
com.example.sumrak.Lists.DataPlayer playerDbEntity);
Ниже прикладываю исходные код:
Класс DataBase.kt
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@Database (entities = [PlayerDbEntity::class], version = 1)
abstract class DataBase : RoomDatabase() {
abstract fun getDao():DaoPlayerDb
companion object{
fun getDb(context: Context) : DataBase{
return Room.databaseBuilder(
context.applicationContext,
DataBase::class.java,
"DataBase"
).build()
}
}
}
Класс PlayerDbEntity.kt
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.example.sumrak.Lists.DataPlayer
@Entity(
tableName = "PlayersTab"
)
data class PlayerDbEntity(
@PrimaryKey(autoGenerate = true) val id : Int? = null,
val name_player : String,
val db : Int,
val bb : Int,
val power : Int,
val dexterity : Int,
val volition : Int,
val endurance : Int,
val intelect : Int,
val insihgt : Int,
val observation : Int,
val chsarisma : Int,
val hp : Int,
val max_hp : Int,
val light_karm : Int,
val dark_karm : Int,
val fate : Int,
val max_fate : Int,
val influence : Int,
val xp : Int
) {
fun toDataPlayer() : DataPlayer = DataPlayer(
id = id,
name_player = name_player,
db = db,
bb = bb,
power = power,
dexterity = dexterity,
volition = volition,
endurance = endurance,
intelect = intelect,
insihgt = insihgt,
observation = observation,
chsarisma = chsarisma,
hp = hp,
max_hp = max_hp,
light_karm = light_karm,
dark_karm = dark_karm,
fate = fate,
max_fate = max_fate,
influence = influence,
xp = xp
)
}
Класс DaoPlayerDb.kt
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import com.example.sumrak.Lists.DataPlayer
import kotlinx.coroutines.flow.Flow
@Dao
interface DaoPlayerDb {
@Insert
fun insertPlayer(playerDbEntity: DataPlayer)
@Query("SELECT * FROM playerstab")
fun getAllPlayer(): Flow<List<PlayerDbEntity>>
}