saving . . . saved Error while using text! has been deleted. Error while using text! has been hidden .
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 12-05-20, 6:28 a.m. satrishabh

Answers:

Check the ID fieldnamemyFirstTextView.It is case sensitive.

Type myFirstTextView.
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.
14-05-20, 4:42 p.m. NirmalaVenkat
Same here. Even the ID is same, it is showing error.
07-05-21, 9:19 p.m. Sujan_A_T

Login to add comment


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.

1) In your module level build.gradle at modeule level in "android" tag add
   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"


25-05-21, 6:15 p.m. smohorikar@gmail.com
What is the meaning of below code :
  val binding = ActivityFirstBinding.inflate(layoutInflater)
        binding.myFirstTextView.text = "Hello, your text here"
05-07-21, 1:51 p.m. Shivang123
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
05-07-21, 1:57 p.m. Shivang123

Login to add comment


Log-in to answer to this question.