Issue
I am trying to run Android app in kotlin. But Mainactivity.kt is not recognizing the ID in Android studio kotlin.
I have tried many ways doing this to solve this error. i even tried to go in build and click on clean project, then, rebuild projects.
but the error wouldn't budge it is still there. i have entered the id of TextView in MainActivity.kt but it still showing in red!
how may i resolve it please help!
Solution
I tested the code for Kotlin version 1.4.1 and it worked perfectly well.
To resolve your error, you can use val tv:TextView = findViewById(R.id.tv_content)
and use tv in your code.
Second option is that you classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20"
in your build.gradle file to classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10"
As stated by @Jimale Abdi -
kotlinx.android.synthetic is no longer a recommended practice. Removing in favour of explicit findViewById.
Hope this helps.
Answered By - mayank1513
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.