App not working at Listing 12.16, Can't register the DAO to the database

I am at chapter 12 coroutines and databases trying to create and use a Room database.
I can add the dependencies (page 393 - Listing 12.8), make Crime an Entity (Listing 12.10), create the CrimeDatabase class and the type converters and create the CrimeDAO, the app still launch correctly, but when i register the DAO into the database (Listing 12.16) nothing works anymore i get a bunch of errors (see screenshot).

  • Not sure how to convert a Cursor to this method’s return type (java.lang.Object). -<? super java.util.List<>>)
  • 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: arg0 -<? super java.util.List<>>)
  • Not sure how to convert a Cursor to this method’s return type (java.lang.Object). -, kotlin.coroutines.Continuation<? super>)
  • Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :id. -, kotlin.coroutines.Continuation<? super>)
  • Unused parameters: arg0,arg1 -, kotlin.coroutines.Continuation<? super>)

Sorry to hear that you are running into issues with Room. That is a common place in which readers have encountered difficulties. My best recommendation is to update the versions of libraries used in the project (see: CrimeDao can't be built witih suspend functions - #5 by bryansillsbnr) but also look through other posts in this forum. Many other people have found solutions to similar problems.

That’s your advice… “Search my forum”! Let’s be serious here this book is used in actual colleges for entire courses on programming, when you screw the schools with books filled of non-working examples then the school screw us with books that don’t prepare us for any exam. A lot of us take our studies seriously and i for one would expect you when we tell you some example is not working, that you answer with a working updated version that will work.

1 Like

The book has been out for a year and a half, which means the contents are about 2 years old. Operating systems, APIs, and programming tools change over time; it’s pretty normal after 2 years for some things to start to be out of date & not work quite right anymore. You just have to learn to roll with that stuff & expect to do a bit of work to figure it out. Really your professors should be the ones telling you how to deal with it, that’s their job.

I’m sorry that you are feeling frustrated about this. As a professional Android developer, trust me when I say this: I have been in your position before. It is annoying. I don’t like it either. But the advice of “search my forum” is a serious recommendation. If you want to continue learning how to make Android apps, you will need to learn how to find answers to your problems and learn how to parse answers that others give you. There is a ton of outdated (and bad) information out there and it takes skill and experience to sort through it all.

Also, the tone in your message is towing the line with what we expect in this community. Please remember to be kind and thoughtful in all your interactions here.

Which is still not an answer to the actual problem. Thanks i’ll go look for another book!

1 Like

Try update room implementation to the newer verion. In my case changed to
and all works.

I published a workaround here: Fix for Chapter 12 build errors: "Not sure how to convert a Cursor" build error