Search code examples
androidkotlinandroid-roommobile-developmentandroid-database

room does not show and suggest table name when use query(SELECT * FROM table_name)


image 1 description : when I want to query : (https://i.sstatic.net/zniPt.png)

image 2 description : the picture android developer has provided : (https://i.sstatic.net/6XXgb.png)

When I query to select all my Items, it does not show my table and also as you see my query text color not change to orange( as it seem in the second picture provide by android developer site )

My Plugins

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
}

My dependency for room

dependencies {

    implementation "androidx.room:room-runtime:2.5.1"
    kapt "androidx.room:room-compiler:2.5.1"
    
    ...
}

my data Class

@Entity(tableName = "table_note")
data class NoteData(

    @PrimaryKey(true)
    val id :Int? = null ,

    val title: String,
    val details: String,
    val date: String,
    val time: String,
    val noteColor: Int
)

my dao

@Dao
interface Dao {

    @Query("SELECT * FROM table_note")
    fun getAllNote() : List<NoteData>

}

well actually I tried to complete my database with this problem. so I inserted an item to my database and call my getAllNote Function to see if it return a result or not and it returned correctly!!

the question is why it does not show my table? I even made another project but It was like this one.

I appreciate if you know the problem or you are serious that it does not have any problem tell me.


Solution

  • Change the room_version to 2.4.3, the actual problem lies in the dependency version 2.5.1.

    Also, try to match your app-level build.gradle file with this one. Hope it works!.

    
    plugins {
        id 'com.android.application'
        id 'org.jetbrains.kotlin.android'
        id "org.jetbrains.kotlin.kapt"
    }
    .
    .
    .
    
    dependencies {
    
      // Room Database
        def room_version = "2.4.3"
        implementation "androidx.room:room-runtime:$room_version"
        // To use Kotlin annotation processing tool (kapt)
        kapt "androidx.room:room-compiler:$room_version"
    
    
        // Kotlin core
        implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
        // Kotlin coroutines for Android
        implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
    
    }