A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction?java.lang.reflect.Invocation?
I fixed it my problem by updating current kotlin version to latest version and moshi version to 1.12.0
I am facing this error A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
at first you have to use @TypeConverter from room because room can not insert the custom types like List or object or bitmap. So firstly make a class named converter then add this class in database using annotation @TypeConverters.
here is the code
Converter.kt
class Converter {
@TypeConverter
fun fromActor(actor: List<Actor>):String{
val type = object : TypeToken<List<Actor>>() {}.type
return Gson().toJson(actor,type)
}
@TypeConverter
fun toActor(actorString: String): List<Actor>{
val type = object : TypeToken<List<Actor>>() {}.type
return Gson().fromJson<List<Actor>>(actorString,type)
}
}
and finally add this converter.kt class in your database
MovieDatabase.kt
@Database(
entities = [Movie::class],
version = 1
)
@TypeConverters(Converter::class)
abstract class MovieDatabase : RoomDatabase() {
abstract fun getMovieDao(): MovieDao
companion object {
@Volatile
private var instance: MovieDatabase? = null
private val LOCK = Any()
operator fun invoke(context: Context) = instance
?: synchronized(LOCK) {
instance
?: buildDatabase(context).also {
instance = it
}
}
private fun buildDatabase(context: Context) = Room.databaseBuilder(
context.applicationContext,
MovieDatabase::class.java,
"movieDatabase"
).build()
}
}
Thank you.
Related Topics
Apache Http Connection with Android 6.0 (Marshmallow)
Get File Path of Image on Android
Mediarecorder Start Failed: -38
Android Devices with Different Height Takes Same Layout Folder
Android Volley Self Signed Https Trust Anchor for Certification Path Not Found
What's the Maximum Size for an Android Shared Preference Value
Google Maps API V2 'Failed to Load Map. Could Not Contact Google Servers'
Jpeg Images Have Different Pixel Values Across Multiple Devices
Mapview Rendering with Tiles Missing with an "X" in the Center
How to Keep a Countdowntimer Running Even If the App Is Closed
Replacing Glreadpixels with Egl_Khr_Image_Base for Faster Pixel Copy
Mediaplayer.Setdatasource Causes Ioexception for Valid File
Android Intent.Getstringextra() Returns Null
Getactionbar() Returns Null (Appcompat-V7 21)
How to Check If Facebook Is Installed Android
What Is a Full Android Database Helper Class for an Existing SQLite Database