Not sure how to convert a Cursor to this method's return type (java.lang.Object)

Hello everyone, I’m new to this so I have some problems.

When I finished 12.23 Accessing your database, when I ran the app I got this:

and this:

package com.bignerdranch.android.criminalintent.database;

import java.lang.System;

@androidx.room.Dao()
@kotlin.Metadata(mv = {1, 8, 0}, k = 1, d1 = {"\u0000 \n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010 \n\u0002\b\u0002\bg\u0018\u00002\u00020\u0001J\u0019\u0010\u0002\u001a\u00020\u00032\u0006\u0010\u0004\u001a\u00020\u0005H\u00a7@\u00f8\u0001\u0000\u00a2\u0006\u0002\u0010\u0006J\u0017\u0010\u0007\u001a\b\u0012\u0004\u0012\u00020\u00030\bH\u00a7@\u00f8\u0001\u0000\u00a2\u0006\u0002\u0010\t\u0082\u0002\u0004\n\u0002\b\u0019\u00a8\u0006\n"}, d2 = {"Lcom/bignerdranch/android/criminalintent/database/CrimeDao;", "", "getCrime", "Lcom/bignerdranch/android/criminalintent/Crime;", "id", "Ljava/util/UUID;", "(Ljava/util/UUID;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "getCrimes", "", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "app_debug"})
public abstract interface CrimeDao {
    
    @org.jetbrains.annotations.Nullable()
    @androidx.room.Query(value = "SELECT * from crime")
    public abstract java.lang.Object getCrimes(@org.jetbrains.annotations.NotNull()
    kotlin.coroutines.Continuation<? super java.util.List<com.bignerdranch.android.criminalintent.Crime>> continuation);
    
    @org.jetbrains.annotations.Nullable()
    @androidx.room.Query(value = "SELECT * FROM crime WHERE id=(:id)")
    public abstract java.lang.Object getCrime(@org.jetbrains.annotations.NotNull()
    java.util.UUID id, @org.jetbrains.annotations.NotNull()
    kotlin.coroutines.Continuation<? super com.bignerdranch.android.criminalintent.Crime> continuation);
}

How do I fix this, thanks.

I’m not sure exactly what is happening here, but the error: “Query method parameters should either be a type that can be converted…” sticks out to me.

Can you share what your Crime and CrimeDao files look like? Also how did you apply your CrimeTypeConverters type converters?

Sure, here is Crime.kt:

@Entity
data class Crime (
@PrimaryKey val id: UUID,
val title: String,
val date: Date,
val isSolved: Boolean
)

and here is CrimeDao.kt:

@Dao
interface CrimeDao {
    @Query("SELECT * from crime")
    suspend fun getCrimes(): List<Crime>

    @Query("SELECT * FROM crime WHERE id=(:id)")
    suspend fun getCrime(id: UUID): Crime
}

And for that last question, I just used them in CrimeDatabase:

@Database(entities = [ Crime::class ], version=1)
@TypeConverters(CrimeTypeConverters::class)
abstract class CrimeDatabase : RoomDatabase() {
    abstract fun crimeDao(): CrimeDao
}

Also when I imported into assets ‘crime-database’, I get a question mark for what type should the file be, and I don’t know either.

All of that looks good. Can you share the code for CrimeTypeConverters too?

Also when I imported into assets ‘crime-database’, I get a question mark for what type should the file be, and I don’t know either.

Android Studio doesn’t have the capability to read that data itself, so it is OK to have that question mark. Android Studio knows that the file needs to be included in the compiled app, and it can handle that. If you want to look at the contents of that file, you could use a website like this: SQLite Viewer