尝试读取 editText 内容时,AlertDialog(Material) 崩溃。
警报对话框:
MaterialAlertDialogBuilder(activity)
.setTitle(title)
.setMessage(message)
.setView(R.layout.dialog_settings_entry)
.setPositiveButton(getString(R.string.text_change)) { dialog, which ->
etUserInput.hint = message
sgr = etUserInput.text.toString() // << crashes here
dialog.dismiss()
}
.setNegativeButton(getString(android.R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}
.show()
单击肯定按钮后,结果如下:
java.lang.IllegalStateException: etUserInput must not be null
at com.home.profile.SettingsFragment$buildAlertDialog$1.onClick(SettingsFragment.kt:332)
at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
etUserInput是单独布局中的简单 editText 。不确定崩溃原因。将不胜感激任何洞察它或任何有用的材料样本。