import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity("matches")
data class MatchEntity(
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "id") val id: Int,
@ColumnInfo(name = "name") val name: String,
@ColumnInfo(name = "city") val city: String,
@ColumnInfo(name = "distance") val distance: Int,
@ColumnInfo(name = "description") val description: String,
@ColumnInfo(name = "score") val score: Int,
@ColumnInfo(name = "age") val age: Int,
@ColumnInfo(name = "body_type") val bodyType: BodyType,
@ColumnInfo(name = "height") val height: Float,
@ColumnInfo(name = "diet") val diet: DietType,
@ColumnInfo(name = "zodiac_sign") val zodiacSign: ZodiacSign,
@ColumnInfo(name = "religion") val religion: Religion,
@ColumnInfo(name = "drinking_habit") val drinkingHabit: DrinkingHabit,
@ColumnInfo(name = "smoking_habit") val smokingHabit: SmokingHabit,
@ColumnInfo(name = "mbti_type") val mbtiType: MbtiType,
@ColumnInfo(name = "enneagram") val enneagram: Enneagram,
@ColumnInfo(name = "kids_type") val kidsType: KidsType,
)
< /code>
для моего класса DAO: < /p>
@Dao
interface MatchDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(matchEntity: MatchEntity): Long
@Update
suspend fun update(matchEntity: MatchEntity): Int
@Delete
suspend fun delete(matchEntity: MatchEntity)
@Query("SELECT * FROM matches")
suspend fun getAll(): List
@Query("SELECT * FROM matches WHERE id = :id")
suspend fun getById(id: Int): List
}
< /code>
для моего класса в разделе «Комната»: < /p>
@Suppress("TooManyFunctions")
@Database(
entities = [
MatchEntity::class, MatchIceBreakerEntity::class, MatchInterestEntity::class,
MatchScheduleEntity::class, MatchSocialEntity::class, MatchStoryEntity::class,
UserEntity::class, UserIceBreakerEntity::class, UserInterestEntity::class,
UserSocialEntity::class, UserStoryEntity::class
],
exportSchema = false,
version = 1
)
@TypeConverters(
BodyTypeConverter::class,
DietTypeConverter::class,
DrinkingHabitConverter::class,
EnneagramConverter::class,
KidsTypeConverter::class,
MbtiTraitConverter::class,
MbtiTypeConverter::class,
ReligionConverter::class,
SleepingHabitConverter::class,
SmokingHabitConverter::class,
SocialConverter::class,
SocialMediaFrequencyConverter::class,
WorkoutTypeConverter::class,
ZodiacSignConverter::class
)
abstract class WingmanDatabase : RoomDatabase() {
abstract fun matchDao(): MatchDao
abstract fun matchIceBreakerDao(): MatchIceBreakerDao
abstract fun matchInterestDao(): MatchInterestDao
abstract fun matchScheduleDao(): MatchScheduleDao
abstract fun matchSocialDao(): MatchSocialDao
abstract fun matchStoryDao(): MatcStoryDao
abstract fun userDao(): UserDao
abstract fun userIceBreakerDao(): UserIceBreakerDao
abstract fun userInterestDao(): UserInterestDao
abstract fun userSocialDao(): UserSocialDao
abstract fun userStoryDao(): UserStoryDao
companion object {
const val DATABASE_NAME: String = "wingman_db"
}
}
< /code>
Для моих зависимостей: < /p>
plugins {
...
id 'kotlin-kapt'
}
...
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
...
dependencies {
...
def room_version = "2.5.1"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"
}
< /code>
для моих плагинов build.gradle: < /p>
plugins {
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
id 'androidx.navigation.safeargs' version '2.5.3' apply false
id 'org.jetbrains.kotlin.android' version '1.9.0-Beta' apply false
}
< /code>
Я работал с комнатой много раз, но на этот раз я получаю эту ошибку: < /p>
C:\Users\Leona\workspace\wingman\app\build\tmp\kapt3\stubs\debug\com\hikarisource\wingman\data\local\dao\MatchDao.java:27: error: Not sure how to convert a Cursor to this method's return type (java.lang.Object).
public abstract java.lang.Object getAll(@org.jetbrains.annotations.NotNull
< /code>
C:\Users\Leona\workspace\wingman\app\build\tmp\kapt3\stubs\debug\com\hikarisource\wingman\data\local\dao\MatchDao.java:28: error: Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type. You can consider adding a Type Adapter for this.
kotlin.coroutines.Continuation
Подробнее здесь: [url]https://stackoverflow.com/questions/76374381/room-not-sure-how-to-convert-a-cursor-to-this-methods-return-type-java-lang[/url]
Я создаю проект с комнатой, и у меня есть следующие коды: < /p> Для моего класса сущности: < /p> [code]import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey
@Entity("matches") data class MatchEntity( @PrimaryKey(autoGenerate = true) @ColumnInfo(name = "id") val id: Int, @ColumnInfo(name = "name") val name: String, @ColumnInfo(name = "city") val city: String, @ColumnInfo(name = "distance") val distance: Int, @ColumnInfo(name = "description") val description: String, @ColumnInfo(name = "score") val score: Int, @ColumnInfo(name = "age") val age: Int, @ColumnInfo(name = "body_type") val bodyType: BodyType, @ColumnInfo(name = "height") val height: Float, @ColumnInfo(name = "diet") val diet: DietType, @ColumnInfo(name = "zodiac_sign") val zodiacSign: ZodiacSign, @ColumnInfo(name = "religion") val religion: Religion, @ColumnInfo(name = "drinking_habit") val drinkingHabit: DrinkingHabit, @ColumnInfo(name = "smoking_habit") val smokingHabit: SmokingHabit, @ColumnInfo(name = "mbti_type") val mbtiType: MbtiType, @ColumnInfo(name = "enneagram") val enneagram: Enneagram, @ColumnInfo(name = "kids_type") val kidsType: KidsType, ) < /code>
для моего класса DAO: < /p> @Dao interface MatchDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insert(matchEntity: MatchEntity): Long
@Update suspend fun update(matchEntity: MatchEntity): Int
@Delete suspend fun delete(matchEntity: MatchEntity)
@Query("SELECT * FROM matches") suspend fun getAll(): List
@Query("SELECT * FROM matches WHERE id = :id") suspend fun getById(id: Int): List } < /code>
abstract fun matchDao(): MatchDao abstract fun matchIceBreakerDao(): MatchIceBreakerDao abstract fun matchInterestDao(): MatchInterestDao abstract fun matchScheduleDao(): MatchScheduleDao abstract fun matchSocialDao(): MatchSocialDao abstract fun matchStoryDao(): MatcStoryDao abstract fun userDao(): UserDao abstract fun userIceBreakerDao(): UserIceBreakerDao abstract fun userInterestDao(): UserInterestDao abstract fun userSocialDao(): UserSocialDao abstract fun userStoryDao(): UserStoryDao
для моих плагинов build.gradle: < /p> plugins { id 'com.android.application' version '8.0.1' apply false id 'com.android.library' version '8.0.1' apply false id 'androidx.navigation.safeargs' version '2.5.3' apply false id 'org.jetbrains.kotlin.android' version '1.9.0-Beta' apply false } < /code>
Я работал с комнатой много раз, но на этот раз я получаю эту ошибку: < /p> C:\Users\Leona\workspace\wingman\app\build\tmp\kapt3\stubs\debug\com\hikarisource\wingman\data\local\dao\MatchDao.java:27: error: Not sure how to convert a Cursor to this method's return type (java.lang.Object). public abstract java.lang.Object getAll(@org.jetbrains.annotations.NotNull < /code>
C:\Users\Leona\workspace\wingman\app\build\tmp\kapt3\stubs\debug\com\hikarisource\wingman\data\local\dao\MatchDao.java:28: error: Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type. You can consider adding a Type Adapter for this. kotlin.coroutines.Continuation
Error:Not sure how to convert a Cursor to this method's return type
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Использование комнаты Я получаю эту ошибку и хочу...
Столкнувшись с проблемой с приложением для практики, над которым я работаю. Я сталкиваюсь с проблемой NullPointerException, связанной с методом ToString. Будучи новым в разработке приложений Android, я не уверен в точной причине даже после моего...