final EditText edt =findViewById(R.id.type_text);
final TextView txt= findViewById(R.id.empty_text);
Button btn = findViewById(R.id.button_add);
final String value = edt.getText().toString();
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
txt.append(value+"\n");
edt.setText("");
}
});
这是第 40 行 --> final EditText edt =findViewById(R.id.type_text);
Logcat 消息
引起:java.lang.ClassCastException:
android.support.design.widget.TextInputLayout 无法转换为 android.widget.EditText
在 com.example.todo.activitity2.onCreate(activitity2.java:40)
最佳答案
在您的布局 XML 文件中,有一个 ID 为 type_text
的 TextInputLayout,您正试图将其转换为 EditText。
在您的 XML 文件中将此 TextInputLayout 更改为 EditText
或
在您的 Class.java 文件中更正此:
final EditText edt = findViewById(R.id.type_text);
到
final TextInputLayout your_name = findViewById(R.id.type_text);
关于java - 需要帮助理解 logcat 消息 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55439325/