英文:
Cannot resolve method makeText in Android
问题
尝试 1:
if ((fieldvalue.getText().toString()).matches("")) {
Toast.makeText(this, "您未输入用户名",
Toast.LENGTH_SHORT).show();
return;
}
尝试 2:
if ((fieldvalue.getText().toString()).matches("")) {
public static Toast makeText (this, "您未输入用户名",
Toast.LENGTH_SHORT);
return;
}
注意:尝试 2 中的代码似乎存在错误,无法正确执行。
英文:
I was trying to play with an android toast. But encountered a problem saying Cannot resolve method makeText
. I searched and found many answers but not a single worked for me.
Try 1:
if ((fieldvalue.getText().toString()).matches("")) {
Toast.makeText(this, "You did not enter a username",
Toast.LENGTH_SHORT).show();
return;
}
Try 2:
if ((fieldvalue.getText().toString()).matches("")) {
public static Toast makeText (this, "You did not enter a username",
Toast.LENGTH_SHORT);
return;
}
答案1
得分: 1
尝试使用isEmpty()
。同时确保使用.this
来定义activityclass
,例如yourclass.this
。
if (fieldvalue.getText().toString().isEmpty()) {
Toast.makeText(youractivity.this, "您未输入用户名!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(youractivity.this, "成功! :)", Toast.LENGTH_SHORT).show();
}
英文:
Try using isEmpty()
. Also make sure to define the activityclass with .this
like yourclass.this
.
if(fieldvalue.getText().toString().isEmpty()) {
Toast.makeText(youractivity.this, "You did not enter a username!", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(youractivity.this, "Success! :)", Toast.LENGTH_SHORT).show();
}
答案2
得分: -2
Sure, here's the translated code:
if (fieldvalue.getText().toString().trim().isEmpty()) {
Toast.makeText(this, "您未输入用户名", Toast.LENGTH_SHORT).show();
return;
}
英文:
if (fieldvalue.getText().toString().trim().isEmpty()) {
Toast.makeText(this, "You did not enter a username", Toast.LENGTH_SHORT).show();
return;
}
专注分享java语言的经验与见解,让所有开发者获益!
评论