英文:
android studio not recognizing(change in color) and suggesting SQLite commands in room @Query() annotation
问题
Student.kt
@Entity(tableName = "student_table")
data class Student(
@PrimaryKey(autoGenerate = true) val id: Int?,
@ColumnInfo(name = "first_name") val firstName: String?,
@ColumnInfo(name = "last_name") val lastName: String?,
@ColumnInfo(name = "roll_no") val rollNo: Int?
)
StudentDao.kt
@Dao
interface StudentDao {
@Query("SELECT * FROM student_table")
fun getAll(): List<Student>
@Query("SELECT * FROM student_table WHERE roll_no LIKE :roll LIMIT 1")
suspend fun findByRoll(roll: Int): Student
}
Build Output(31 tasks were UP-TO-DATE, I didn't mention them below)
> Task :app:createDebugVariantModel UP-TO-DATE
> Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:processDebugMainManifest
> Task :app:processDebugManifest
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:mergeDebugNativeLibs NO-SOURCE
> Task :app:stripDebugDebugSymbols NO-SOURCE
> Task :app:processDebugManifestForPackage
> Task :app:processDebugResources
> Task :app:packageDebug
> Task :app:createDebugApkListingFileRedirect
> Task :app:assembleDebug
BUILD SUCCESSFUL in 1m 19s
37 actionable tasks: 6 executed, 31 up-to-date
Build Analyzer results available
In StudentDao.kt file @Query() annotation is not recognizing SQLite query, for example, "student_table" (as table name) and is not highlighting SQLite queries like SELECT.
英文:
Student.kt
@Entity(tableName = "student_table")
data class Student(
@PrimaryKey(autoGenerate = true) val id:Int?,
@ColumnInfo(name = "first_name") val firstName:String?,
@ColumnInfo(name = "last_name") val lastName:String?,
@ColumnInfo(name = "roll_no") val rollNo:Int?
)
StudentDao.kt
@Dao
interface StudentDao {
@Query("SELECT * FROM student_table")
fun getAll(): List<Student>
@Query("SELECT * FROM student_table WHERE roll_no LIKE :roll LIMIT 1")
suspend fun findByRoll(roll: Int): Student
Build Output(31 tasks were UP-TO-DATE, i didn't mentioned them below)
> Task :app:createDebugVariantModel UP-TO-DATE
> Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:processDebugMainManifest
> Task :app:processDebugManifest
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:mergeDebugNativeLibs NO-SOURCE
> Task :app:stripDebugDebugSymbols NO-SOURCE
> Task :app:processDebugManifestForPackage
> Task :app:processDebugResources
> Task :app:packageDebug
> Task :app:createDebugApkListingFileRedirect
> Task :app:assembleDebug
BUILD SUCCESSFUL in 1m 19s
37 actionable tasks: 6 executed, 31 up-to-date
Build Analyzer results available
In StudentDao.kt file @Query() annotation not recognizing SQLite query ex. student_table(as table name) & not highlighting SQLite queries like SELECT.
答案1
得分: 1
我通过尝试不同版本的房间解决了这个问题。之前,我使用的是截止到2023年3月的最新版本2.5.0。
def room_version = "2.4.0";
implementation "androidx.room:room-runtime:$room_version";
ksp "androidx.room:room-compiler:$room_version";
implementation "androidx.room:room-ktx:$room_version";
英文:
i solved this problem by trying different versions of room. previously i was using latest version which was 2.5.0 as of march 2023
def room_version = "2.4.0"
implementation "androidx.room:room-runtime:$room_version"
ksp "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
答案2
得分: 0
只编译项目,这将在构建日志中显示大多数实际问题。
有时候,编辑器内部的检查并不总是完全全面的,接受这一点可能会更简单。我发现修改代码,然后编译(CTRL + F9),然后检查构建日志是最有效的策略。
英文:
Simply compile the project, that will raise most actual issues in the build log.
It could be simplest to accept that at times the underlying checking within the editor is not always fully comprehensive. I find that change code then compile (CTRL + F9) and then check the build log is the most effective policy.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论