Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialheinz meza
1,121 Pointsnot sure how to solve this: Toast allDoneToast; Toast.makeText(this, "All done!", Toast.LENGTH_LONG).show();
How to solve this? ...I'm getting an error. Please Help!!!
Toast allDoneToast;
Toast.makeText(this, "All done!", Toast.LENGTH_LONG).show();
Toast allDoneToast;
Toast.makeText(this, "All done!", Toast.LENGTH_LONG).show();
1 Answer
Steve Hunter
57,712 PointsHi there,
There's two steps to this.
First, set up the Toast and store it in the variable provided. Then call the .show()
method on the variable:
Toast allDoneToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG);
allDoneToast.show();
Hope that helps .
Steve.
Steve Hunter
57,712 PointsThe last part of the challenge then requires you to combine the Toast
call into one line - that's what you did in the second line of your initial post.
Derek Markman
16,291 PointsSteve, would my syntax have worked as well? Can you concatenate the .show() method on the end like that?
Steve Hunter
57,712 PointsI don't think so as it would fire the Toast too soon.. The .show()
method displays the Toast; you called that immediately so, whilst in this set of code the toast was called immediately after it was created, it is possible that the Toast would be further called elsewhere in the code.
I'm not sure what your code actually assigns to the variable allDoneToast
- I don't know what's left after the .show()
method is called. So it is possible that the contents of allDoneToast
aren't what's expected for the code to operate as intended.
Make sense?
Steve.
Derek Markman
16,291 PointsHow does the java compiler read java code? Left to right?
In my example I didn't assign the allDoneToast variable to anything I was just declaring it. Then initializing it below. Which is what I believe @heinz meza was trying to do, the only thing that looked wrong about their syntax was they never assigned the allDoneToast variable to anything, they just declared it.
Steve Hunter
57,712 PointsNot wholly sure. I would imagine it'll take the code a line at a time within each code block. But, yes, for our ease of use implying a left to right reading style makes sense - certainly for the direction of assignments etc.
So, x = y, assigns the value of y into x.
Derek Markman
16,291 PointsDerek Markman
16,291 PointsI believe it's not working because you need to reference the Toast variable "allDoneToast" you just declared. Other than that your syntax looks correct.
For any further info on Toasts, you can refer to the link below, which directs you to the android docs. http://developer.android.com/guide/topics/ui/notifiers/toasts.html