Android Studio没有识别到颜色变化并在Room @Query()注解中建议SQLite命令。

huangapple go评论54阅读模式
英文:

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 = &quot;student_table&quot;)
data class Student(
    @PrimaryKey(autoGenerate = true) val id:Int?,
    @ColumnInfo(name = &quot;first_name&quot;) val firstName:String?,
    @ColumnInfo(name = &quot;last_name&quot;) val lastName:String?,
    @ColumnInfo(name = &quot;roll_no&quot;) val rollNo:Int?
)

StudentDao.kt

@Dao
interface StudentDao {

    @Query(&quot;SELECT * FROM student_table&quot;)
    fun getAll(): List&lt;Student&gt;

    @Query(&quot;SELECT * FROM student_table WHERE roll_no LIKE :roll LIMIT 1&quot;)
    suspend fun findByRoll(roll: Int): Student

Build Output(31 tasks were UP-TO-DATE, i didn't mentioned them below)

&gt; Task :app:createDebugVariantModel UP-TO-DATE
&gt; Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
&gt; Task :app:compileDebugAidl NO-SOURCE
&gt; Task :app:compileDebugRenderscript NO-SOURCE
&gt; Task :app:processDebugMainManifest
&gt; Task :app:processDebugManifest
&gt; Task :app:compileDebugShaders NO-SOURCE
&gt; Task :app:processDebugJavaRes NO-SOURCE
&gt; Task :app:mergeDebugNativeLibs NO-SOURCE
&gt; Task :app:stripDebugDebugSymbols NO-SOURCE
&gt; Task :app:processDebugManifestForPackage
&gt; Task :app:processDebugResources
&gt; Task :app:packageDebug
&gt; Task :app:createDebugApkListingFileRedirect
&gt; 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 = &quot;2.4.0&quot;
implementation &quot;androidx.room:room-runtime:$room_version&quot;
ksp &quot;androidx.room:room-compiler:$room_version&quot;
implementation &quot;androidx.room:room-ktx:$room_version&quot;

答案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.

huangapple
  • 本文由 发表于 2023年2月10日 14:36:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75407669.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定