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 trialoscar gonzalez
7,072 Pointsi got troubles with the toast i got the last version of andriod when Ben add the line of Toast it doesn't appear
this is my code line Toast.makeText(MainActivity.this, name , Toast.LENGTH_LONG).show(); it suppose that with this line my Toast would appear but it doesn't work help!!!
i got the last version of androis i run up my app it run ok, but when i press the button it doesn't work as ben did!!!
1 Answer
Steve Hunter
57,712 PointsHi Oscar,
That code looks fine, as long as name
is a String. You shouldn't need the MainActivity
bit as that's where you are running the Toast
but that should make no difference.
So, can you show the rest of your code, please. It isn't the Toast
that's not working - it is something else. If you can paste in all of your onCreate()
method, the issue is likely to lie in there.
Thanks,
Steve.
oscar gonzalez
7,072 Pointsoscar gonzalez
7,072 PointsThanks steve for your answer, yes i added another line of code and with this line works great first declared a context class final Context context = getApplicationContext(); and the toast was defined like this: Toast.makeText(context, name , toast.LENGTH_LONG).show();
i tested and every thing is working good!
Thanks for your time steve happy coding!!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsThat's odd but I'm glad you got it working.
You shouldn't need to type anything other than
this
` for the first parameter as the context is in that activity.At least it's working!