我是编码的新手,当时我在android studio中编码一个聊天应用程序。我当时在编码,当我在其他字词下方插入红线时,我想知道您是否可以帮助我摆脱这些行。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
username = findViewById(R.id.username);
email = findViewById(R.id.email);
passward = findViewById(R.id.passward);
btn_register = findViewById(R.id.btn_register);
auth = FirebaseAuth.getInstance();
btn_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String txt_username = username.getText().toString();
String txt_email = email.getText().toString();
String txt_passward = passward.getText().toString();
if ((TextUtils.isEmpty(txt_username) || (TextUtils.isEmpty(txt_email) || (TextUtils.isEmpty(txt_passward)){
Toast.makeText(RegisterActivity.this, "All fields are required", Toast.LENGTH_SHORT).show();
} else if (txt_passward.length() < 6 ){
Toast.makeText(RegisterActivity.this, "Passward must be atleast 6 chracters", Toast.LENGTH_SHORT).show();
} else {
register(txt_username, txt_email, txt_passward);
}
}
});
}
红线显示在else下方,并且显示错误“ else if if”
答案 0 :(得分:0)
在第一个条件下,您会错过三个右括号。
只需尝试
if ((TextUtils.isEmpty(txt_username)) || (TextUtils.isEmpty(txt_email)) || (TextUtils.isEmpty(txt_passward)))
答案 1 :(得分:0)
尝试删除括号
if ( (TextUtils.isEmpty(txt_username)) ||
(TextUtils.isEmpty(txt_email)) ||
(TextUtils.isEmpty(txt_passward)) )
{
//
}