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

not sure how to do these challenges,tasks 1,2, and 3?

Set the Toast variable using the static makeText() method of the Toast class. Use the this keyword for the first parameter, the text "All done!" for the second parameter, and the constant Toast.LENGTH_LONG for the third parameter….thats is what I'm supposed to do, and I'm sure i won't be able to do the next tasks either, if you could please help me on these three tasks it would be wonderful, thanks

Toast allDoneToast;

3 Answers

Stefan Kiehnle
Stefan Kiehnle
3,105 Points

Basically, you would write the code like this:

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

The makeText() method is a static method for Toast. That's why you call it Toast.makeText(). If makeText() weren't static you would first need to instantiate Toast, as this: Toast toast = new Toast() and then you would call toast.makeText(). As for the parameters, those are the data you would pass to a method, for the method to be able to do its work correctly. So, the first parameters is this, because this refers to the Activity (technically, you need to pass a Context object, but since Activity inherits from Context, everything's good by just calling this). In the second parameter, you specify what message you would like the Toast to display, and the third parameter refers to how long you want the Toast to show up (it can either be LENGTH_SHORT or LENGTH_LONG).

Hope it helps, enjoy coding. :)

i copied and pasted what you told me, ansi got this error message?

JavaTester.java:84: error: variable allDoneToast might not have been initialized else if (allDoneToast.mConstructorCalled) { ^ 1 error

i finally figured it out ….this worked

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

i didn't put the (=).

I was trying to start it all on a new line. thanks for your help