I’m learning how to implement Room from Android jetpack into my android studio app but a message saying "not enough information to infer type variable T" keeps showing up when I try to use Room.databaseBuilder
this is my code:
// if there is no instance, we create a new one
synchronized(this){
val instance = Room.databaseBuilder(
context.applicationContext,
UserDatabase::class.java,
"user_database"
).build()
INSTANCE = instance
return instance
}
I can add the surrounding function or the whole file if that helps. Thanks in advance!
2
Answers
I’m not sure but this is the problem i faced as well and i solved it by downgrading
'implementation 'androidx.core:core-ktx:1.6.0'
to'implementation 'androidx.core:core-ktx:1.5.0'
in the build.gradle fileIf you have for example:-
The you get the
not enough information to infer type variable T
e.g. :-Changing to use the same class then all is fine, e.g.
As a test/proof consider :-
The result (ignore TheDatabase as existing code was used for the answer) :-