Issue
class MainActivity : AppCompatActivity() {
lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater, AppCompatActivity(),true)
setContentView(binding.root)
}
Solution
Try to inflate your layout with ActivityMainBinding.inflate(layoutInflater)
and make the binding
variable private:
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
}
Answered By - Luca Pizzini
Answer Checked By - Marilyn (JavaFixing Volunteer)