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

zivasorn
zivasorn
615 Points

Need some help with the Challenge - Task 3 of 3 in the "Toast Notifications chapter" of the "Build an Android App"

How to chain the show() method to the makeText() method?

6 Answers

Hi Ziva,

I re-did the challenge, and i used the below commands, have a look:

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

String message = "Your message"; Toast.makeText(MainActivity.this, message,message.LENGTH_LONG).show();

For more info or applying more features, have a look at this website: http://developer.android.com/guide/topics/ui/notifiers/toasts.html

My mistake: it should not be message.LENGTH_LONG but Toast.LENGTH_LONG;

zivasorn
zivasorn
615 Points

Hi Ali,

Tnx for helping me. That's what I thought, but I keep getting a compiler error.

I've added your code to an existing code: String message = "All done!"; Toast allDoneToast = Toast.makeText(this,message,Toast.LENGTH_LONG); allDoneToast.show(); Toast.makeText(this,"All done!", Toast.LENGTH_LONG).show();; String message = "Your message"; Toast.makeText(MainActivity.this, message,Toast.LENGTH_LONG).show();

And the error report says (I've been getting the "variable message is already defined in method run" all the time): JavaTester.java:79: error: variable message is already defined in method run() String message = "Your message"; Toast.makeText(MainActivity.this, message,Toast.LENGTH_LONG).show(); ^ JavaTester.java:79: error: cannot find symbol String message = "Your message"; Toast.makeText(MainActivity.this, message,Toast.LENGTH_LONG).show(); ^ symbol: class MainActivity location: class JavaTester 2 errors

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

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

Yey! indeed :) It worked. I see it know. Thanks so much. Have a lovely evening (6.22 p.m. over here)