我在这件事上失去了理智。我收到错误消息“变量‘joiningDate’可能尚未初始化”。这是代码:
private TextView joiningDate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_registration);
joiningDate = findViewById(R.id.joiningDate);
}
private void saveData() {
String name = editTextName.getText().toString();
String email = editTextEmail.getText().toString();
String phone = editTextPhone.getText().toString();
String userId = editTextUserId.getText().toString();
String password = editTextPassword.getText().toString();
String joiningDate = joiningDate.getText().toString();
// Now send this data to your server
sendDataToServer(name, email, phone, userId, password, joiningDate);
}
请帮我解决它。
您使用与文本视图相同的字符串名称。使用不同的名称而不是 joinDate
String joinDate = joiningDate.getText().toString();