EN VI

I couldnt genarate view binding in kotlin?

2024-03-17 22:30:05
How to I couldnt genarate view binding in kotlin

enter image description here

When I try genarate view binding for kotlin, its giving red line on inflate and I cannot run project.

package com.example.wiewbinding

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.renderscript.ScriptGroup.Binding
import com.example.wiewbinding.databinding.ActivityMainBinding



class MainActivity : AppCompatActivity() {

    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        val view = binding.root
        setContentView(view)

    }
}

How to fix that?

Android doc is not work properly I think. We have to find way to use

Solution:

In this case, you don't need to import it explicitly. Check once, if in build.gradle file, is the view Binding is enabled or not. After this rebuild it and check if the red line issue is resolve or not and let me know

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login