any idea why I’m getting this exception when tryin...
# android
o
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
Are you using Instant Run?
l
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
yes it’s there, if you look at the first file I linked to
and I am using instant run, yea
l
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
if I use kapt, I get a kaptDebugKotlin internal compiler error
l
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
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
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
yeah you're right, returning a List<T> should work
o
yea, it does
l
so everything is working now 😄?
o
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
some of Room warnings are good to improve your db performance though
I used only once, but's really cool
o
and this is for the “Multiple good constructors” warning https://stackoverflow.com/a/44620836/764897