Search code examples
android-studioandroid-room

android studio: error: Cannot figure out how to read this field from a cursor



I have a scenario where i read data from a Room database in a special read object.
meaning because i wanted to read from 2 table (join) and put the result in 1 object i created a seperte read object and of cource 2 "write" objects (1 for each table). Now that all worked great until i add a private var to the read object. Then i got the error from the title.
In my search i created a simple example to rule out any other mistakes i have made
class ReadObject ( var id: Long,
                   var description: String?,
                   var relationOf: Int,
                   var namerelation: String ) {....}

The above works great. On the place of the .... i have some constructor variants and some helper functions.
But when i do this:

class ReadObject ( var id: Long,
                   var description: String?,
                   var relationOf: Int,
                   var namerelation: String ) { private var tester: Int = 0 .... }

i get the message from the title.
of course i am not reading the 'tester' from the database it is an internal helper-var for the object and not a database field.
I seems strange that private vars are not allowed when an object is used to read from the database so i must be doing something wrong. Just cannot figure out what.
There are some other posts about the same error but they describe a different situation.

Hope somebody can help


Solution

  • Found the solution the scientific-way (try and try again)
    Adding the @Ignore before the declaration of the private var solves the error.
    I do not understand why beceause the private var is not in declaration of the object but sometimes you just need to accept things.