JetPack Bugs
JetPack Bugs
Room Persistence: Error:Entities and Pojos must have a usable public constructor
@Ignore 应该放到类中声明
error:
@Entity(tableName = "t_user")
data class User(
@PrimaryKey @ColumnInfo(name = "uid") var uid: Long,
@ColumnInfo(name = "first_name") var firstName: String?,
@ColumnInfo(name = "last_name") var lastName: String?,
@Ignore var picture: Bitmap? = null
)
success:
@Entity(tableName = "t_user")
data class User(
@PrimaryKey @ColumnInfo(name = "uid") var uid: Long,
@ColumnInfo(name = "first_name") var firstName: String?,
@ColumnInfo(name = "last_name") var lastName: String?
) {
@Ignore
var picture: Bitmap? = null
//or
// constructor() : this(0, "", "")
}
Not sure how to convert a Cursor to this method's return type
val allUsers: LiveData<List<User>> = userDao.getAll()
error:
@Query("select * from t_user order by uid asc")
fun getAll(): MutableLiveData<List<User>>
success:
@Query("select * from t_user order by uid asc")
fun getAll(): LiveData<List<User>>
Android ViewModel has no zero argument constructor
https://stackoverflow.com/questions/44194579/android-viewmodel-has-no-zero-argument-constructor
For lifecycle_version = '2.2.0' ViewProviders.of API is deprecated . It`s my situation :
class MainActivityViewModel(application: Application) : AndroidViewModel(application) {
private var repository: UserRepository
val allUsers: LiveData<List<User>>
......
error:
val userViewModel = ViewModelProvider(this).get(MainActivityViewModel::class.java)
success:
val factory = ViewModelProvider.AndroidViewModelFactory.getInstance(application)
userViewModel = ViewModelProvider(this,factory).get(MainActivityViewModel::class.java)
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.
改了 data class User 中的字段,但是没有更新 version
Primary key constraint on id is ignored when being merged into com.ando.jetpack.room.User
An @Embedded field cannot contain Primary Key.
error
@Entity(tableName = "t_user")
data class User(
@ColumnInfo(name = "uid") @PrimaryKey var uid: Long?,
@Embedded var address: Address? = null
)
error also
@Entity(tableName = "t_user")
data class User(
@ColumnInfo(name = "uid") @PrimaryKey var uid: Long?,
@SuppressWarnings(RoomWarnings.PRIMARY_KEY_FROM_EMBEDDED_IS_DROPPED)
@Embedded var address: Address? = null
)
success
@SuppressWarnings(RoomWarnings.PRIMARY_KEY_FROM_EMBEDDED_IS_DROPPED)
@Entity(tableName = "t_user")
data class User(
@ColumnInfo(name = "uid") @PrimaryKey var uid: Long?,
@Embedded var address: Address? = null
)
A field can be annotated with only one of the following:ColumnInfo,Embedded,Relation
error
@Entity(tableName = "t_user")
data class User(
@ColumnInfo(name = "uid") @PrimaryKey var uid: Long?,
@ColumnInfo(name = "address") @Embedded var address: Address? = null
)
success
@Entity(tableName = "t_user")
data class User(
@ColumnInfo(name = "uid") @PrimaryKey var uid: Long?,
@Embedded var address: Address? = null
)
There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such table: t_book)
You should mention both the entities in your roomDatabase class.
@Database(entities = {BaseWordId.class, ABC.class}, version = VERSION_CODE, exportSchema = false)
public abstract class YourDatabase extends RoomDatabase {
//your Daos
}
The column songId in the junction entity com.ando.jetpack.room.PlaylistSongCrossRef is being used to resolve a relationship but it is not covered by any index.
This might cause a full table scan when resolving the relationship, it is highly advised to create an index that covers this column.
warn
@Entity(primaryKeys = ["playlistId", "songId"])
data class PlaylistSongCrossRef(
val playlistId: Long,
val songId: Long
)
no warn
@Entity(primaryKeys = ["playlistId", "songId"])
data class PlaylistSongCrossRef(
val playlistId: Long,
@ColumnInfo(index = true) val songId: Long
)
[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).
禁用增量注解 : gradle.properties add kapt.incremental.apt=false

浙公网安备 33010602011771号