Can’t Access XML form Main Activity in Android Studio [closed]

Tags: , , , ,



I cannot access the elements in my XML form the main activity, writing the element id throws errors as if the element is not even there. Basically Main can’t see what is written in XML file, even though they are linked.

Can’t detect the getBmiButton button from XML

Button was defined here

Answer

you Don’t need findViewById() anymore. You should Integrate Kotlin Android Extensions by adding these lines to build.gradle (app)

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

and use your view as a property. If you are curious how this works, this article will help you.



Source: stackoverflow