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

Question about where to put code

How come at times, we put the code inside the onCreate method but at other times, we put it right underneath it after the curly brace has closed? I'm confused because there are times when Ben says let's put this in the onCreate method, but the code written is outside of the onCreate method.

2 Answers

Could you possible give an example of one of these code samples you mention? Generally there shouldn't be code outside of either the onCreate() method or some other method within the class - except for all your instance variable declarations etc. at the top.

Dan,

I would recommend reading these two links. They are very helpful on the description of the syntax for Methods and Classes. Hope this helps!

Classes: http://docs.oracle.com/javase/tutorial/java/javaOO/

Methods: http://docs.oracle.com/javase/tutorial/java/javaOO/methods.html