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

James N
James N
17,864 Points

i need help

i need help . i do not understand the error i'm getting. here is my error: JavaTester.java:40: variable allDoneToast might not have been initialized else if (allDoneToast.mConstructorCalled) { ^ 1 error here is my code: Toast allDoneToast; Toast.makeText(this, "All done!", Toast.LENGTH_LONG).show();

1 Answer

Stone Preston
Stone Preston
42,016 Points

what task are you on? you are getting the error because you declare the variable allDoneToast but never assign it anything. if its task 1 you need to assign your second line to the declaration on the first. you also dont need to show it yet

//this never gets assigned
Toast allDoneToast;
Toast.makeText(this, "All done!", Toast.LENGTH_LONG).show();

to fix it just assign it the second like but remove the call to show

Toast allDoneToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG);
James N
James N
17,864 Points

thanks. i was on task 1

James N
James N
17,864 Points

now i am getting this error: JavaTester.java:32: incompatible types found : void required: Toast Toast smiley = Toast.makeText(this, ":)", Toast.LENGTH_LONG).show(); ^ 1 error with this code: Toast allDoneToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG); allDoneToast.show(); Toast smiley = Toast.makeText(this, ":)", Toast.LENGTH_LONG).show(); in task 3.

Stone Preston
Stone Preston
42,016 Points

you almost have it, you dont need to assign your third toast statement to a variable.

Toast allDoneToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG);
allDoneToast.show();
//since you are chaining the makeText and show methods in one line, you dont need to assign it anything. 
Toast.makeText(this, ":)", Toast.LENGTH_LONG).show();
James N
James N
17,864 Points

THANK YOU SO MUCH!!!