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 trialzivasorn
615 PointsNeed 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
Ali Saif
14,567 PointsHi 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();
Ali Saif
14,567 PointsString 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
Ali Saif
14,567 PointsMy mistake: it should not be message.LENGTH_LONG but Toast.LENGTH_LONG;
zivasorn
615 PointsHi 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
Ali Saif
14,567 Points'''Toast allDoneToast = Toast.makeText(this,"All done!",Toast.LENGTH_LONG); allDoneToast.show(); Toast.makeText(this,"Yay!",Toast.LENGTH_LONG).show();'''
Ali Saif
14,567 PointsToast allDoneToast = Toast.makeText(this,"All done!",Toast.LENGTH_LONG);
allDoneToast.show();
Toast.makeText(this,"Yay!",Toast.LENGTH_LONG).show();
zivasorn
615 PointsYey! indeed :) It worked. I see it know. Thanks so much. Have a lovely evening (6.22 p.m. over here)