jskubick

jskubick

Kotlin and Android Development featuring Jetpack: Error in generated Game.java (page 136)

I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to build without errors.

Reasons for the assumption:

  • The Database Inspector ISN’T appearing (as far as I can tell, in Arctic Fox, it was moved to the “App Inspection” tab and no longer exists as a Tool window of its own).

  • I assume the act of successfully building and running the app is what creates and populates the database on the emulator, and…

  • once that database exists, Android Studio notices it & reveals the Database Inspector functionality.

There are no visible errors in the sourcecode itself (no red squiggly lines in any editable source files, no red marks along the right margin), but I’m getting a slew of errors in the generated app/build/tmp/kapt3/stubs/debug/dev/mfazio/pennydrop/data/Game.java class, PennyDropDao.java, and Player.java (note: all are *.java and presumably generated, the *.kt files seem to be fine) that I’m not sure how to troubleshoot:

C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:7: warning: There are multiple good constructors and Room will pick the no-arg constructor. You can use the @Ignore annotation to eliminate unwanted constructors.
public final class Game {
             ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:11: error: Cannot find setter for field.
    private final dev.mfazio.pennydrop.data.GameState gameState = null;
                                                      ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:13: error: Cannot find setter for field.
    private final java.time.OffsetDateTime startTime = null;
                                           ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:15: error: Cannot find setter for field.
    private final java.time.OffsetDateTime endTime = null;
                                           ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:17: error: Cannot find setter for field.
    private final java.util.List<java.lang.Integer> filledSlots = null;
                                                    ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:19: error: Cannot find setter for field.
    private final java.lang.Integer lastRoll = null;
                                    ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:21: error: Cannot find setter for field.
    private final java.lang.String currentTurnText = null;
                                   ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:22: error: Cannot find setter for field.
    private final boolean canRoll = false;
                          ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:23: error: Cannot find setter for field.
    private final boolean canPass = false;
                          ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:7: warning: There are multiple good constructors and Room will pick the no-arg constructor. You can use the @Ignore annotation to eliminate unwanted constructors.
public final class Game {
             ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:11: error: Cannot find setter for field.
    private final dev.mfazio.pennydrop.data.GameState gameState = null;
                                                      ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:13: error: Cannot find setter for field.
    private final java.time.OffsetDateTime startTime = null;
                                           ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:15: error: Cannot find setter for field.
    private final java.time.OffsetDateTime endTime = null;
                                           ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:17: error: Cannot find setter for field.
    private final java.util.List<java.lang.Integer> filledSlots = null;
                                                    ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:19: error: Cannot find setter for field.
    private final java.lang.Integer lastRoll = null;
                                    ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:21: error: Cannot find setter for field.
    private final java.lang.String currentTurnText = null;
                                   ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:22: error: Cannot find setter for field.
    private final boolean canRoll = false;
                          ^
C:\src\experiments\android\PennyDrop\app\build\tmp\kapt3\stubs\debug\dev\mfazio\pennydrop\data\Game.java:23: error: Cannot find setter for field.
    private final boolean canPass = false;
                          

Any idea which class to even start looking at to figure out what’s wrong? I’m guessing I forgot an annotation somewhere… or possibly, in an attempt to fix an earlier typo problem by copying files from the .zip file, might have created a bigger one by prematurely copying something mentioned later in the chapter that’s now triggering the error above by expecting the presence of something that officially hasn’t been added yet as of page 136.

For what it’s worth, it looks like the following methods of PennyDropDao.kt haven’t yet been mentioned as of page 136, but are in the .zip file’s version, and the references to them by the lines added prior to page 136 will generate errors in PennyDropDao.kt itself unless they’re added:

getPlayer()
insertGame()
insertPlayer()
insertPlayers()
updateGame()

According to WinMerge, my versions of Converters.kt, Game.kt, GameState.kt, GameStatus.kt, PennyDropDatabase.kt, and PennyDropRepository.kt are presently identical to the versions in the zipfile.

As far as I can recall, my copy of PennyDropDao.kt was identical, until I commented the methods out, then went through chapter 5 from the start and moved the methods from inside the comment block to the outside in the order they’re mentioned in the chapter. That’s how I noticed that 5 methods listed above were referenced by the code, but not mentioned yet as of page 136… they were still in the comment block as of page 136.

Marked As Solved

mfazio23

mfazio23

Author of Kotlin and Android Development featuring Jetpack

Jeff, I think I got it. The book was written against Room 2.3.0-beta01 which doesn’t play nice with Kotlin 1.5.30. If you upgrade your Room dependency to 2.3.0, it should work without trouble.

Please let me know either way!

Also Liked

mfazio23

mfazio23

Author of Kotlin and Android Development featuring Jetpack

Hey Jeff,
I’m looking through what you have here and I’m trying to figure out what’s going on.

The first thing I want to hit are those five functions from PennyDropDao. All five are on pages 118 and 119 when we first create the abstract class. Are these the functions you’re referencing here?

The issue with the Game class looks familiar from my initial development work, though I do not remember what caused that specific problem. Could you share what your Game class looks like? And an offer: if you wanted to upload your work to GitHub or something similar, I’d be willing to troubleshoot things that way with you. I want to make sure you can get as much as possible out of the book.

For reference, you’re right on point with the *.java files being generated. :+1: Also, you’re correct on the Database Inspector being moved in Arctic Fox. I’m really starting to dislike this new Android Studio update.

Let me know on your Game class (and if you want to put the whole project out somewhere I can access it) and we’ll go from there!

jskubick

jskubick

OK, that fixed it. Thanks!!!

Popular Prag Prog topics Top

jamis
The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New
mikecargal
Title: Hands-on Rust: question about get_component (page 295) (feel free to respond. “You dug you’re own hole… good luck”) I have somet...
New
alanq
This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New
Charles
In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
New
jwandekoken
Book: Programming Phoenix LiveView, page 142 (157/378), file lib/pento_web/live/product_live/form_component.ex, in the function below: d...
New
tkhobbes
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
New
dtonhofer
@parrt In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New

Other popular topics Top

PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
PragmaticBookshelf
A Hero’s Journey with Chris Pine @chrispine Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
AstonJ
Saw this on TikTok of all places! :lol: Anyone heard of them before? Lite:
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New

Latest in PragProg

View all threads ❯