https://kotlinlang.org logo
#android
Title
# android
o

oday

11/07/2017, 10:32 AM
any idea why I’m getting this exception when trying to use Room? http://snpy.in/kK4ueW this is the file in question https://github.com/Odaym/Snipit-Kotlin/blob/master/app/src/main/kotlin/com/om/snipit/dagger/BaseModule.kt#L20
l

louiscad

11/07/2017, 10:42 AM
Are you using Instant Run?
l

leosan

11/07/2017, 10:43 AM
are you providing a concrete implementation? something like
Room.databaseBuilder(context,...
?
you must provide it somewhere, usually in your Application class or with dagger
o

oday

11/07/2017, 10:44 AM
yes it’s there, if you look at the first file I linked to
and I am using instant run, yea
l

louiscad

11/07/2017, 10:44 AM
Anyway, there's an obvious issue: you used
annotationProcessor
instead of
kapt
for Room compiler, and tried to use it from Kotlin code: https://github.com/Odaym/Snipit-Kotlin/blob/master/app/build.gradle
Fix this, and try again, it should work.
annotationProcessor
only processes java sources.
kapt
processes both Kotlin and Java, so use it if you want to generate from Kotlin annotated code
o

oday

11/07/2017, 10:45 AM
if I use kapt, I get a kaptDebugKotlin internal compiler error
l

louiscad

11/07/2017, 10:46 AM
Because there's error(s) in your code. If you scroll up the logs (available in Gradle console in Android Studio), you'll see the exact errors that cause kapt to stop
l

leosan

11/07/2017, 10:47 AM
probably because your provide method must be static ( I'm not sure about this 😛 I'm not good with dagger)
but my guess would be : 1- change your module class to
object
and use
@JvmStatic
in your provide method or 2- create a
companion object
annotate it with
@Module
, put your provide method there and annotate it with
@JvmStatic
o

oday

11/07/2017, 11:33 AM
yea the problems were all inside the gradle console, I mean I’ve seen them before but I didn’t know how to react to them
first of all, all the params to the model classes were
val
, and even though I did provide default values to them, there was not setter for them, so I changed them all to
var
second of all, I was returning ArrayList<T> for my queries in the DAO’s, should’ve been Cursor
third, I was referencing a foreign key in another table, and in that other table, the ID I was referencing was not indexed, that one was a warning
Although about the returning a Cursor, this shouldn’t be the case, I should be able to return a List<T> just fine
l

leosan

11/07/2017, 11:38 AM
yeah you're right, returning a List<T> should work
o

oday

11/07/2017, 11:38 AM
yea, it does
l

leosan

11/07/2017, 11:38 AM
so everything is working now 😄?
o

oday

11/07/2017, 11:38 AM
any idea what these mean though? https://hastebin.com/ejoyuqucaq.http
they are still warnings
yea the app runs now, just have to take the DB access off the main thread
👍 1
l

leosan

11/07/2017, 11:39 AM
some of Room warnings are good to improve your db performance though
I used only once, but's really cool
o

oday

11/07/2017, 11:47 AM
and this is for the “Multiple good constructors” warning https://stackoverflow.com/a/44620836/764897
3 Views