'How to solve E/RecyclerView: No adapter attached; skipping layout after after percelize the fragment?
Can anyone tell me what's wrong with my build.gradle? How can I solve the error? I have tried a lot to solve this problem but failed all the time. Please someone help me to solve this error.................................................................................................................................................................................................................................................................................................
Database
package com.example.noteapp.DataBase
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.noteapp.dao.NotesDao
import com.example.noteapp.model.Notes
@Database(entities = [Notes::class], version = 1, exportSchema = false)
abstract class NotesDataBase : RoomDatabase() {
abstract fun myNotesDao(): NotesDao
companion object{
@Volatile
var INSTANCE : NotesDataBase ?= null;
fun getDataBaseInstance(context: Context) : NotesDataBase {
val tempInstance = INSTANCE
if (tempInstance != null){
return tempInstance
}
synchronized(this)
{
val roomDatabaseInstance = Room.databaseBuilder(context, NotesDataBase::class.java, "Notes").allowMainThreadQueries().build()
INSTANCE = roomDatabaseInstance
return roomDatabaseInstance
}
}
}
}
This is the previous Note Model
package com.example.noteapp.model
import android.graphics.Color
import android.os.Parcel
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "Notes")
class Notes (@PrimaryKey(autoGenerate = true)
var id : Int? = null,
var title : String,
var notes : String,
var date : String,
// need to percelize color var color: Int = -1,
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readString().toString(),
parcel.readString().toString(),
parcel.readString().toString(),
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeValue(id)
parcel.writeString(title)
parcel.writeString(notes)
parcel.writeString(date)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Notes> {
override fun createFromParcel(parcel: Parcel): Notes {
return Notes(parcel)
}
override fun newArray(size: Int): Array<Notes?> {
return arrayOfNulls(size)
}
}
}
New Note Model
package com.example.noteapp.model
import android.graphics.Color
import android.os.Parcel
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "Notes")
class Notes (@PrimaryKey(autoGenerate = true)
var id : Int? = null,
var title : String,
var notes : String,
var date : String,
var color : Int = -1,
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readString().toString(),
parcel.readString().toString(),
parcel.readString().toString(),
parcel.readInt()
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeValue(id)
parcel.writeString(title)
parcel.writeString(notes)
parcel.writeString(date)
parcel.writeInt(color)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Notes> {
override fun createFromParcel(parcel: Parcel): Notes {
return Notes(parcel)
}
override fun newArray(size: Int): Array<Notes?> {
return arrayOfNulls(size)
}
}
}
Solution 1:[1]
I don't think so there is something wrong with your build.gradle
file.
But As I can see that error
Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
in your logcat
It means you have changed something in your Room database
but not changed the version of database. Either try changing the version of Database or Uninstall the app from your device and rerun your project.
Always remember that you have to change the version of RoomDB
every time if you change something in database. Otherwise, it will throw exception.
I hope the issue will be resolved.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tariq Hussain |