One line toasting error in java Incompatible types

When I want to do a one line toast in Java I get this error message:

JavaTester.java:34: incompatible types
found   : void
required: android.widget.Toast
Toast newToast = Toast.makeText(this, "This is a one liner", Toast.LENGTH_LONG).show();
1 error

Has anyone got any idea what I can do to fix this error?

Jon Skeet
people
quotationmark

You're calling the .show() method, which has a void return type. Either don't try to use the result:

Toast.makeText(this, "This is a one liner", Toast.LENGTH_LONG).show();

Or use two statements:

Toast newToast = Toast.makeText(this, "This is a one liner", Toast.LENGTH_LONG);
newToast.show();

people

See more on this question at Stackoverflow