@mfazio23
I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the BaseballDao.java class produced during the build process. I get the following errors:
- Not sure how to convert a Cursor to this method’s return type (java.lang.Object).
- 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.
- Unused parameter: continuation
- Type of the parameter must be a class annotated with @Entity or a collection/array of it.
- Not sure how to handle insert method’s return type.
- Type of the parameter must be a class annotated with @Entity or a collection/array of it.
- Not sure how to handle insert method’s return type.
- Type of the parameter must be a class annotated with @Entity or a collection/array of it.
- Not sure how to handle update method’s return type. Currently the supported return types are void, int or Int.
- Type of the parameter must be a class annotated with @Entity or a collection/array of it.
- Not sure how to handle update method’s return type. Currently the supported return types are void, int or Int.
- The query returns some columns [teamId, division, wins, losses, winsLastTen, streakCount, streakType, divisionGamesBack, leagueGamesBack, id] which are not used by java.lang.Object. You can use @ColumnInfo annotation on the fields to specify the mapping. You can annotate the method with @RewriteQueriesToDropUnusedColumns to direct Room to rewrite your query to avoid fetching unused columns. You can suppress this warning by annotating the method with @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH). Columns returned by the query: teamId, division, wins, losses, winsLastTen, streakCount, streakType, divisionGamesBack, leagueGamesBack, id.
The error message is
C:\Users\ale\AndroidStudioProjects\AndroidBaseballLeague\app\build\tmp\kapt3\stubs\debug\org\mathverse\androidbaseballleague\data\BaseballDao.java:31: error: Not sure how to convert a Cursor to this method’s return type (java.lang.Object).
public abstract java.lang.Object getCurrentStandings(@org.jetbrains.annotations.NotNull()
(I’m using org.mathverse.androidbaseballleague as package name, instead of dev.mfazio.abl).
The BaseballDao.java class contains the following lines
@org.jetbrains.annotations.Nullable()
@androidx.room.Query(value = "SELECT * FROM standings")
public abstract java.lang.Object getCurrentStandings(@org.jetbrains.annotations.NotNull()
kotlin.coroutines.Continuation<? super java.util.List<org.mathverse.androidbaseballleague.standings.TeamStanding>> continuation);
This is the only function of the database having prblems.
How can I solve this issue?
Thanks
Alessandro,
Would you mind sharing your BaseballDao.kt
function declaration? It looks like the auto-implementation is messed up for some reason.
Thanks!
The class definition is the following:
package org.mathverse.androidbaseballleague.data
import androidx.lifecycle.LiveData
import androidx.room.*
import org.mathverse.androidbaseballleague.scoreboard.ScheduledGame
import org.mathverse.androidbaseballleague.standings.TeamStanding
@Dao
abstract class BaseballDao {
@Insert
abstract suspend fun insertStandings(standings: List)
@Update
abstract suspend fun updateStandings(standings: List<TeamStanding>)
@Query("SELECT * FROM standings")
abstract fun getStandings(): LiveData<List<TeamStanding>>
@Query("SELECT * FROM standings")
abstract suspend fun getCurrentStandings(): List<TeamStanding>
@Query("SELECT * FROM games WHERE gameId LIKE :dateString")
abstract fun getGamesForDate(
dateString: String
): LiveData<List<ScheduledGame>>
@Query("SELECT * FROM games WHERE gameId = :gameId")
abstract fun getGameByGameId(gameId: String) : ScheduledGame?
@Insert
abstract suspend fun insertGame(game: ScheduledGame)
@Update
abstract suspend fun updateGame(game: ScheduledGame)
@Transaction
open suspend fun insertOrUpdateGames(games: List<ScheduledGame>) {
games.forEach { game ->
getGameByGameId(game.gameId)?.let { dbGame ->
updateGame(game.apply { id = dbGame.id })
} ?: insertGame(game)
}
}
}
I’m using Android Studio Chipmunk 2021-2.1 Patch 1, and package versions are
kotlin_version = '1.7.10'
gradle_version = '7.2.1'
app_compat_version = '1.4.2'
constraint_layout_version = '2.1.4'
core_version = '1.8.0'
material_version = '1.6.1'
nav_version = '2.5.0'
recycler_view_version = '1.2.1'
room_version = '2.4.2'
abl_client_version = '1.1.1'
retrofit_version = '2.9.0'
swipe_refresh_version = '1.1.0'
Thank you for helping
@mfazio23
Hi Michael,
inspecting BaseballDao.java I observed that all suspend functions have been generated incorrectly, therefore I have looked for similar issues in android issue tracker system: there is an old fixed issue, number 206655922, relating to DAO suspend functions. Since the issue resurfaced, I have opened a new one 239729505 hoping to obtain a fix.
Alessandro,
I’ll have to try this out with the updated libraries. It’s certainly worth a shot getting that new issue out there at the very least.
Michael,
according to comment #11 to issue number 236612358, this problem is related to a change to Kotlin @Metadata annotation and can be solved forcing the dependency to the new version of kotlinx-metadata-jvm by adding
kapt “org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0”
This worked for me and solved another issue (room 2.4.2 didn’t allow to use vals into @Entity data classes asking, for the generated java class, setters for the corresponding variables).
1 Like
I’m marking this last piece as the solution for anyone else that runs into the same problem. Good find!