Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (2014) Testing and Debugging Making a Toast

Bob Boursaw
Bob Boursaw
2,047 Points

Toast.makeText(this, "All done!", Toast.LENGTH_LONG).show(); No idea why this doesn't work.

I am apparently missing something from the course, but I don't understand what it is and have tried about 10 different variants of the code, all failing.

ToastTest.java
Toast allDoneToast;
allDoneToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG).show();

2 Answers

EVGENII MAMONTOV
EVGENII MAMONTOV
7,666 Points

I think you've got incompatible types in your left and right sides of the equation. Toast.makeText(this, "All done!", Toast.LENGTH_LONG) - is the "Toast" type, great. But Toast.makeText(this, "All done!", Toast.LENGTH_LONG).show() returns nothing, it's "void", and cannot be equal to allDoneToast variable of the"Toast" type. Try breaking your operator into two: allDoneToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG); allDoneToast.show();

Alex Johnson
Alex Johnson
6,067 Points

This helped me. Thanks!

Alex Johnson
Alex Johnson
6,067 Points

Update: Turns out that the reason you don't need a variable is because it's a static function of the Toast class so you can call it right from the class without instantiation.

I'm not sure why this didn't work in part one of the challenge, but to pass part three I was able to combine the first two lines into one without referencing a specific variable. This is what I put:

Toast allDoneToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG);
allDoneToast.show();
Toast.makeText(this, "Second toast!", Toast.LENGTH_LONG).show();