无法解析 Android 中的方法 makeText

Cannot resolve method makeText in Android

我正在尝试玩 android 吐司。但是遇到了一个问题 Cannot resolve method makeText。我搜索并找到了很多答案,但没有一个对我有用。

尝试 1:

if ((fieldvalue.getText().toString()).matches("")) {
    Toast.makeText(this, "You did not enter a username", 
    Toast.LENGTH_SHORT).show();
    return;
}

尝试 2:

if ((fieldvalue.getText().toString()).matches("")) {
    public static Toast makeText (this, "You did not enter a username", 
    Toast.LENGTH_SHORT);
    return;
}
if (fieldvalue.getText().toString().trim().isEmpty()) {
    Toast.makeText(this, "You did not enter a username", Toast.LENGTH_SHORT).show();
    return;
}

尝试使用 isEmpty()。还要确保使用 .this 定义活动类,例如 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();
}