创建Toast时出现错误'无法解析方法makeText'

问题描述 投票:0回答:1

当我在这里使用此代码时

Toast.makeText(HomeActivity.this, ""+accountKitError.getErrorType().getMessage());

我收到消息无法解析方法'makeText。这是我的代码:

@Override
public void onError(AccountKitError accountKitError) {
    Toast.makeText(HomeActivity.this, "+accountKitError.getErrorType().getMessage());
}
java android android-studio toast android-toast
1个回答
0
投票

makeText方法采用三个参数:应用程序contexttext消息和用于烤面包的duration。它返回正确初始化的Toast对象。您可以使用show()显示敬酒通知,如以下示例所示:

Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);
toast.show();

在您的情况下,您缺少durationshow(),请像这样添加它们,它将起作用:

Toast.makeText(
    HomeActivity.this, 
    ""+accountKitError.getErrorType().getMessage(),
    Toast.LENGTH_SHORT
).show();

这里是文档的链接,以获取有关Toasts的更多信息:https://developer.android.com/guide/topics/ui/notifiers/toasts#java

© www.soinside.com 2019 - 2024. All rights reserved.