kotlin 如何修复错误(未解析的引用:editText问题)在安卓系统中?

gfttwv5a  于 2023-02-19  发布在  Kotlin
关注(0)|答案(1)|浏览(171)

kotlin-android-extensions Gradle插件已弃用。请使用this migration guide开始使用View Bindingkotlin-parcelize插件。

C:\\Users\\ADMINISTRATOR\\AndroidStudioProjects\\MyApplication4\\app\\src
\\main\\java\\com\\denizas\\myapplication\\MainActivity.kt: (14, 21):
Unresolved reference: editText

Caused by: org.gradle.api.GradleException:
Compilation error. See log for more details
hgqdbh6s

hgqdbh6s1#

build.gradle(模块:应用)

android {
....
buildFeatures {
            viewBinding true
        }
}

MainActivity.kt

class MainActivity : AppCompatActivity() {

private var _binding: ActivityMainBinding? = null
    private val binding
        get() = _binding!!

override fun onCreate(savedInstanceState: Bundle?) { 
super.onCreate(savedInstanceState)
_binding = ActivityChartBinding.inflate(layoutInflater) 
setContentView(R.layout.activity_main) 
} 
fun topla(view: View){
binding.apply {
//in this part it is used to access the views in the layout part
       var sayi1 = editText.text.toStirng()
      }
  } 
}

相关问题