Error 'Cannot resolve method makeText' when creating a Toast

Jhumildes :

When I use this code here

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

I get a message Cannot resolve method 'makeText. This is my code:

@Override
public void onError(AccountKitError accountKitError) {
    Toast.makeText(HomeActivity.this, "+accountKitError.getErrorType().getMessage());
}
Mohamad Assem Nasser :

makeText method takes three parameters: the application context, the text message, and the duration for the toast. It returns a properly initialized Toast object. You can display the toast notification with show(), as shown in the following example:

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

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

In your case, you were missing the duration and the show(), add them like this and it will work:

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

Here is a link to the docs for more information about Toasts: https://developer.android.com/guide/topics/ui/notifiers/toasts#java

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=34689&siteId=1