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

Serkan Erip
Serkan Erip
1,274 Points

Why don't run this code

Where i am making mistake

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

4 Answers

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

If you want to display a toast, all you have to do is use what is on the right side of the '=' sign. There is no need to store it in a variable.

Toast.makeText(this,"ALL DONE!",Toast.LENGTH_LONG).show();
Seth Kroger
Seth Kroger
56,403 Points

The challenge checker needs the allDoneToast variable to check that the Toast is being set up properly in prior stages. Otherwise, yeah the one line solution is better.

Jon Kussmann
Jon Kussmann
Courses Plus Student 7,254 Points

Good point. I didn't check the instructions for the challenge.

Seth Kroger
Seth Kroger
56,403 Points

The "Toast allDoneToast =" part is expecting the expression that follows to return a Toast but the final method of the chain, show(), returns void. To make the challenge work you should split it into two lines.

Toast allDoneToast = Toast.makeText(this,"ALL DONE!",Toast.LENGTH_LONG);
allDoneToast.show();

Did you get any output when you tried:

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

I got a compile error with no output.

Serkan Erip
Serkan Erip
1,274 Points

You're right but i am take compiler error! JavaTester.java:85: error: cannot find symbol else if (allDoneToast.mConstructorCalled) { ^ symbol: variable allDoneToast location: class JavaTester JavaTester.java:85: error: illegal start of type else if (allDoneToast.mConstructorCalled) { ^ JavaTester.java:88: error: cannot find symbol else if (!(allDoneToast.mContext instanceof JavaTester)) { ^ symbol: variable allDoneToast location: class JavaTester JavaTester.java:91: error: package allDoneToast does not exist else if (!allDoneToast.mText.toUpperCase().equals("ALL DONE!")) { ^ JavaTester.java:94: error: cannot find symbol else if (allDoneToast.mDuration == LENGTH_LONG) { ^ symbol: variable allDoneToast location: class JavaTester JavaTester.java:97: error: cannot find symbol else if (allDoneToast.mDuration != Toast.LENGTH_LONG) { ^ symbol: variable allDoneToast location: class JavaTester 6 errors

Serkan Erip
Serkan Erip
1,274 Points

Sorry sorry i wrong understand because my english not well, i solved thank you for your comment!