Android Kotlin Infotainment app with ROOM DB – error: Not sure how to convert a Cursor to this method’s return type (java.lang.Object)

I am new to Android infotainment app development, I am storing the data in DB and get the data from DB and place the data in Google maps using PlaceListMapTemplate.

below is my LocationEntity DB class,

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "locations")
data class LocationEntity(
    @PrimaryKey(autoGenerate = true) val id: Int = 0,
    val latitude: Double,
    val longitude: Double,
    val radius: Float
)

below is my Interface LocationDao,

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query

@Dao
interface LocationDao {
    @Insert
    suspend fun insertLocation(location: LocationEntity)

    @Query("SELECT * FROM locations")
    suspend fun getAllLocations(): List<LocationEntity>
}

below is my app database class,

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

@Database(entities = [LocationEntity::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {
    abstract fun locationDao(): LocationDao

    companion object {
        @Volatile
        private var INSTANCE: AppDatabase? = null

        fun getDatabase(context: Context): AppDatabase {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    AppDatabase::class.java,
                    "GMADDA"
                ).build()
                INSTANCE = instance
                instance
            }
        }
    }
}

Below is the LocationRepository,

class LocationRepository(private val locationDao: LocationDao) {

    suspend fun insertLocation(location: LocationEntity) {
        locationDao.insertLocation(location)
    }

    suspend fun getAllLocations(): List<LocationEntity> {
        return locationDao.getAllLocations()
    }
}

below is the LocationViewModel,

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

class LocationViewModelFactory(private val repository: LocationRepository) : ViewModelProvider.Factory {
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(LocationViewModel::class.java)) {
            @Suppress("UNCHECKED_CAST")
            return LocationViewModel(repository) as T
        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }
}

below is the infotainment class where PlaceListMapTemplate is used,

import android.location.Location
import androidx.car.app.CarContext
import androidx.car.app.Screen
import androidx.car.app.model.Action
import androidx.car.app.model.CarIcon
import androidx.car.app.model.CarLocation
import androidx.car.app.model.ItemList
import androidx.car.app.model.MessageTemplate
import androidx.car.app.model.Place
import androidx.car.app.model.PlaceListMapTemplate
import androidx.car.app.model.Row
import androidx.car.app.model.Template
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.lifecycleScope
import com.example.ddainfotainment.RepositoryUtils.setUpObserversAndCallApi
import com.example.ddainfotainment.Utils.goToHome
import com.example.ddainfotainment.db.LocationEntity
import com.example.ddainfotainment.db.LocationViewModel
import com.example.ddainfotainment.db.LocationViewModelFactory
import com.example.ddainfotainment.db.MyApplication
import com.example.ddainfotainment.model.WeatherResModel
import kotlinx.coroutines.launch

class PlaceListMapExample4(carContext: CarContext) : Screen(carContext),
    DefaultLifecycleObserver {

    private var weatherResponseModelData: WeatherResModel? = null
    private var currentLocation: Location? = null
    private var mIsLoading = true
    private var errorMessage: String? = null

    private val locationViewModel: LocationViewModel

    init {
        val repository = (carContext.applicationContext as MyApplication).repository
        val factory = LocationViewModelFactory(repository)
        locationViewModel = ViewModelProvider(carContext as ViewModelStoreOwner, factory).get(LocationViewModel::class.java)

        // Insert sample location
        lifecycleScope.launch {
            val location = LocationEntity(latitude = 37.7749, longitude = -122.4194, radius = 10F)
            locationViewModel.insertLocation(location)
        }

        lifecycle.addObserver(this)
    }

    private fun isLocationChanged(newLocation: Location): Boolean {
        return currentLocation?.run { latitude != newLocation.latitude || longitude != newLocation.longitude }
            ?: true
    }

    private val loadingCallback: (Boolean) -> Unit = { isLoading ->
        mIsLoading = isLoading
        if (isLoading) {
            invalidate()
        }
    }

    private val errorCallback: (String?) -> Unit = { errorData ->
        errorMessage = errorData
        invalidate()
    }

    private val weatherDataCallback: (WeatherResModel?) -> Unit = { weatherResponse ->
        weatherResponseModelData = weatherResponse
        mIsLoading = false
        errorMessage = null
        invalidate()
    }

    private val currentLocationCallback: (Location) -> Unit = { location ->
        if (isLocationChanged(location)) {
            currentLocation = location
            invalidate()
        }
    }

    override fun onGetTemplate(): Template {
        setUpObserversAndCallApi(
            carContext,
            this,
            loadingCallback,
            errorCallback,
            weatherDataCallback,
            currentLocationCallback
        )

        val placeDetailRow = Row.Builder()
        weatherResponseModelData?.let {
            placeDetailRow.addText("${it.name}  ·  ${it.sys.country}")
        }

        val onClickListener: () -> Unit = {
            weatherResponseModelData?.let {
                screenManager.push(PlaceDetailsScreen(carContext, it))
            } ?: run {
                Utility.showErrorMessage(
                    carContext,
                    carContext.getString(R.string.loading_status)
                )
            }
        }

        val builder = PlaceListMapTemplate.Builder()
        if (mIsLoading) {
            return builder.run {
                setLoading(true)
                setTitle(carContext.getString(R.string.my_location))
                setHeaderAction(Action.BACK)
                build()
            }
        }

        errorMessage?.let {
            return MessageTemplate.Builder(it).run {
                setTitle(Constants.PLACE_LIST_MAP_TEMPLATE)
                setIcon(CarIcon.ERROR)
                setHeaderAction(Action.BACK)
                setActionStrip(goToHome(carContext, this@PlaceListMapExample4))
                addAction(RepositoryUtils.getRetryAction(carContext, this@PlaceListMapExample4))
                build()
            }
        }

        builder.setItemList(
            ItemList.Builder()
                .addItem(
                    placeDetailRow.run {
                        setTitle(carContext.getString(R.string.browse_place_details))
                        setBrowsable(true)
                        setOnClickListener(onClickListener)
                        build()
                    }
                )
                .build()
        )
            .setTitle(carContext.getString(R.string.my_location))
            .setHeaderAction(Action.BACK)

        currentLocation?.let {
            builder.setAnchor(
                Place.Builder(CarLocation.create(it)).build()
            )
        }
        return builder.build()
    }
}

below is the exception which I am getting,

error: Not sure how to convert a Cursor to this method's return type (java.lang.Object).
    public abstract java.lang.Object getAllLocations(@org.jetbrains.annotations.NotNull

Could any one please help me on this, thanks in Advance

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật