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

Ben Mair
Ben Mair
8,728 Points

Toast Statment

I get it! But having an issue........

ToastTest.java
String message = "All done!";
Toast allDoneToast = Toast.makeText(this,message, Toast.LENGTH_LONG);
String mMessage = "I Love Life";
Toast nextDoneToast = Toast.makeText(this,mMessage,Toast.LENGTH.LONG);
nextDoneToast + allDoneToast.show();

2 Answers

Marcus Eley
Marcus Eley
16,213 Points

Hello Ben,

That code looks good, there is just one thing that is easy to overlook. Your use of the LENGTH_LONG constant in the second toast here:

Toast nextDoneToast = Toast.makeText(this,mMessage,Toast.LENGTH.LONG);

You used a period instead of an underscore. I make this kind of typo all the time.

I hope this helps,

Marcus

I'm sorry, I seemed to have confused myself as well. After tinkering a bit I came up with this in Android Studio that worked for the toasts.

   String message = "All done!";
   String mMessage = "I love life!";
    Toast allDoneToast = Toast.makeText(this, message , Toast.LENGTH_LONG);
    Toast nextDoneToast = Toast.makeText(this, mMessage, Toast.LENGTH_LONG);
    nextDoneToast.show();
    allDoneToast.show();

What I think the problem might be is that you are trying to run this line here:

nextDoneToast + allDoneToast.show();

I couldn't seem to get it to run that way. Perhaps java doesn't recognize that. I don't know.

Also, you can reduce this to two lines:

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

Toast.makeText(this, "I love life!", Toast.LENGTH_LONG).show();

I hope that helps, sorry about my confusing myself and presenting an incomplete answer before.

Marcus

Ben Mair
Ben Mair
8,728 Points

I fixed that and it still doesnt work????????