When building the room, there are several small problems. Record them. Basically, it is a configuration problem:
There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such table: simple_student)。
an error is reported during compilation and the table cannot be found
you need to set the corresponding indication in the declared entity.
//Wrong
@Entity
data class StudentEntity
//Right
@Entity(tableName = "student_table")
data class StudentEntity
Not sure how to convert a Cursor to this method’s return type (kotlinx.coroutines.flow.Flow<?extends java.util.List<com.zxf.jetpackrelated.room.liveDataOrFlow.StudentEntity>>).
When the Dao layer declares the return value as livedata, an error is reported. After a long investigation, it was found that the corresponding function was declared as a suspended function
correct use should remove the corresponding suspend modifier.
//Wrong
@Query("select * from $STUDENT_TABLE_NAME")
suspend fun obtainStudentAll(): LiveData<List<StudentEntity>>
//Right
@Query("select * from $STUDENT_TABLE_NAME")
fun obtainStudentAll(): LiveData<List<StudentEntity>>
Not sure how to convert a Cursor to this method’s return type (androidx.lifecycle.LiveData<java.util.List<com.zxf.jetpackrelated.room.liveDataOrFlow.StudentEntity>>)
Similarly, it cannot be converted to flow, and the corresponding suspend modifier is removed.
//Wrong
@Query("select * from $STUDENT_TABLE_NAME")
suspend fun obtainStudentAll(): Flow<List<StudentEntity>>
//Right
@Query("select * from $STUDENT_TABLE_NAME")
fun obtainStudentAll(): Flow<List<StudentEntity>>
If you do not need to declare the return type as livedata or flow, you can directly declare suspend.
Read More:
- How to Solve Android jetpack Room Schema export Error
- How to Solve VMware Workstation Error: This virtual machine appears to be in use.
- How to Solve Error: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- [Solved] Android Room: Database Common Error ‘missing database’
- Room DB Error: AppDatabase_Impl does not exist [How to Solve]
- Nginx: How to Use Error_Page
- How to Solve Error: Type mismatch: cannot convert from Object to Car
- Duplicate entry ‘1’ for key’PRIMARY’ (How to Solve)
- How to Sove Error: listen EADDRINUSE: address already in use 127.0.0.1:8888
- How to Solve AD20 Channel-Offset Error
- Solve the VUE startup problem (You may use special comments to disable some warnings)
- How to Solve Expdp Error ORA-39126
- How to Solve DB2 uses Limit Error
- How to Solve Namedparameterjdbctemplate.queryforobject() Return Error
- How to Solve Error: Unsupported field: HourOfDay
- How to Solve Springboot Error: Failed to convert value of type
- Android 10: How to Solve Systemui Error
- How to Solve PageHelper.startPage count Error
- How to Solve Starrocks Various Error
- How to Solve Logstash error: failed to execute action