I have a layout xml where the following line occurs:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/rootLayout"
...
and in Kotline I have the following line to refer to this element:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val rootLayout = findViewById(R.id.rootLayout)
...
The findViewById function is underlined in red telling
‘Not enough information to infer type variable T’
Why is this happening. Clearly the type should be ‘ConstraintLayout’
Why the error?
2
Answers
Try with this:
Hovering over the red underline should give you the following note:
So you’ve faced the unconstrained case, the reason for which is explained here and can be fixed by specifying the generic type: