Error while using text!
Title
Question
Here while using myFirstTextView.text here text option is not showing and further there is an error after running the program.
Android-app-using-Kotlin Getting-started-with-Hello-World-app 12-13 min 0-10 sec
Answers:
Check the ID fieldnamemyFirstTextView.It is case sensitive.
Type myFirstTextView.
The IDE will show all the attributes of the TextView. Select text.
The IDE will show all the attributes of the TextView. Select text.
For any build errors, close the project and open it again. Then run the program.
If you are using android studio 4.0 and kotlin 1.4 onwards.
This is because kotlin synthetics is no more available which was allowing assignment to TextView (or other elements) as shown in the video.
buildFeatures {
viewBinding = true
}
2) in your FirstActivity.kt file use following instead of directly assigning text.
Make sure you import the dependency when the ActivityFirstBinding turns coloured. Android studio will add import line automatically when you update dependency.
val binding = ActivityFirstBinding.inflate(layoutInflater)
binding.myFirstTextView.text = "Hello, your text here"
What is the meaning of below code :
val binding = ActivityFirstBinding.inflate(layoutInflater)
binding.myFirstTextView.text = "Hello, your text here"
I have used your code :
val binding = ActivityFirstBinding.inflate(layoutInflater)
binding.myFirstTextView.text = "Hello, your text here"
but still I get the Hello World! text whenever I am running the app
Login to add comment
Login to add comment