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 (retired 2014) Interrogating the App Toast Notifications

Inheritance Issues

For the following code I don't quite understand why the commented out code does not work. I mean since allDoneToast is an instance of a Toast; why doesn't makeText() also executes on allDoneToast, and I ned to execute it in Toast and then transfer it along to allDoneToast?

I'm I thinking about it in the right way? or i'm I miles off? :P

/// //Toast allDoneToast.makeText( this, "All Done!",Toast.LENGTH_LONG );

Toast allDoneToast = Toast.makeText( this, "All Done!",Toast.LENGTH_LONG );

1 Answer

dan schmidt
dan schmidt
2,576 Points

My java is even rustier than my ruby, but I thought you would have to instantiate a new instance of Toast to be able to call it's instance methods? Something like:

Toast allDoneToast = new Toast();

allDoneToast.makeText(this, "All Done!", Toast.LENGTH_LONG);

Of course, I have no idea what your constructors look like so how you instatiate Toast objects is probably different than above.

Edit;

Thinking about it some more, is makeText a constructor that you want the subclass allDoneToast to invoke from it's superclass Toast? If that is the case, I'm pretty sure you have to call super from the subclass. See here: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html