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 trial

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

ToastTest.java
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