Reputation: 14711
Toast.makeText(net.asdqwe.activities.Signup.this, configurationz.ERROR_MESSAGES_SIGNUP_PASSWORDS_DO_NOT_MATCH, Toast.LENGTH_SHORT).setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL, 0, 0);
Toast.show();
This code doesnt work. Toast.show() is marked in red with the following error:
Cannot make a static reference to the non-static method show() from the type Toast
Toast.makeText(net.asdqwe.activities.Signup.this,
configurationz.ERROR_MESSAGES_SIGNUP_PASSWORDS_DO_NOT_MATCH,
Toast.LENGTH_SHORT)
.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL, 0, 0)
.show();
This also doesnt work, giving me the following error:
Cannot invoke show() on the primitive type void
Upvotes: 0
Views: 195
Reputation: 28093
show() method is not a static method,So you cant call Toast.show();
Rather you should use following.
Toast toast=Toast.makeText(net.asdqwe.activities.Signup.this, configurationz.ERROR_MESSAGES_SIGNUP_PASSWORDS_DO_NOT_MATCH, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
Upvotes: 1
Reputation: 4497
Show is not a static method, so you need to use the instance you create with the makeText method. This is how you could do it:
Toast myToast = Toast.makeText(net.asdqwe.activities.Signup.this, configurationz.ERROR_MESSAGES_SIGNUP_PASSWORDS_DO_NOT_MATCH, Toast.LENGTH_SHORT);
myToast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL, 0, 0);
myToast.show();
Upvotes: 2