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?
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();
See more on this question at Stackoverflow