Home > Blockchain >  I am getting an error in Kapt Debug Kotlin. I have update versions of dependencies in gradle file. s
I am getting an error in Kapt Debug Kotlin. I have update versions of dependencies in gradle file. s

Time:11-23

My app was running smoothly but I am getting this error now.I am getting an error in Kapt Debug Kotlin. I have update versions of dependencies in gradle file. still facing this issue. How it can be resolved? I saw somewhere to see your room database , dao and data class. still not able to figure out what is the issue.

enter image description here The error is showing this file enter image description here ROOM DATABASE

@Database(entities = [Transaction::class], version = 1, exportSchema = false)
abstract class MoneyDatabase : RoomDatabase(){

    abstract fun transactionListDao():transactionDetailDao
    companion object {
        // Singleton prevents multiple instances of database opening at the
        // same time.
        @Volatile
        private var INSTANCE: MoneyDatabase? = null

        fun getDatabase(context: Context): MoneyDatabase {
            // if the INSTANCE is not null, then return it,
            // if it is, then create the database
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    MoneyDatabase::class.java,
                    "transaction_database"
                ).build()
                INSTANCE = instance
                // return instance
                instance
            }
        }
    }
}

DAO

@Dao
interface transactionDetailDao {
    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun insert(transaction : Transaction)

    @Delete
    suspend fun delete(transaction : Transaction)

    @Update
    suspend fun update(transaction: Transaction)

    @Query("SELECT * FROM transaction_table ORDER BY id ASC")
    fun getalltransaction(): LiveData<List<Transaction>>
}

DATA CLASS

enum class Transaction_type(){
    Cash , debit , Credit
}
enum class Type(){
    Income, Expense
}
@Entity(tableName = "transaction_table")
data class Transaction(
    val name : String,
    val amount : Float,
    val day : Int,
    val month : Int,
    val year : Int,
    val comment: String,
    val datePicker: String,
    val transaction_type : String,
    val category : String,
    val recurring_from : String,
    val recurring_to : String
){
    @PrimaryKey(autoGenerate = true) var id :Long=0
}

CodePudding user response:

The error is resolved. I was using the kotlin version 1.6.0. I reduced it to 1.4.32. As far as I understood, above(latest) version of Kotlin along with Room and coroutines doesn’t work well.

CodePudding user response:

I believe that your issue is due to the use of an incorrect class being inadvertently used, a likely culprit being Transaction as that it also a Room class

Perhaps in transactionDetailDao (although it might be elsewhere)

See if you have import androidx.room.Transaction? (or any other imports with Transaction)?

If so delete or comment out the import

As an example with, and :-

enter image description here

And with the import commented out :-

enter image description here

Imported from github, had a play issue definitely appears to be with co-routines. commented out suspends in the Dao :-

@Dao
interface transactionDetailDao {
    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun insert(transaction : Transaction)

    @Delete
    suspend fun delete(transaction : Transaction)

    @Update
    suspend fun update(transaction: Transaction)

    @Query("SELECT * FROM transaction_table ORDER BY id ASC")
    fun getalltransaction(): LiveData<List<Transaction>>
}

Compiled ok and ran and had a play e.g. :-

enter image description here

  • Related