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 Blog Reader Android App Exploring the Master-Detail Template Adding More Test Data

Determining where a method comes from

I have a really stupid question. In this video Ben references the ``` mCallBacks.onItemSelected(DummyContent.ITEMS.get(position).id);

mCallBacks is declared and initialized on line 33 and is a member of the ListFragment class. I understand that part, but then Ben states to open the ListActivity.java class file. This is where my question lies is how do we know where a method resides within the code. If you mouse over the onItemSelected method on line 119 it does not state that it is actually in the ListActivity class. It would just make it easier in the future to know how he understood so quickly where the method was templated. I dont really care about the where it is constructed, because frankly we can construct an object and method of an object anywhere in our code that the class can be seen. But where is the template of the code made so that we know what it is doing? Does anyone see what I mean? This is completely Ben's fault he is too good... Joking of course

2 Answers

Randy Perez
Randy Perez
5,668 Points

Well imagine you have a class called Tom.java in your sources and this particular class has a method called getTomsName(). Now in your main activity you are referencing that class thought a member variable -> public Tom mTomclass = new Tom(); And then you are using that member variable below in your code to retrieve the name mTomclass. getTomsName(); ? if you hit F3 here you will be redirected to the local declaration of the member variable but just there in the member variable you can hit again F3 and it will take you to the document Tom.java;

Hope it helps

Randy, You Rock! thank you so much I didn't think of pressing it twice thank you for being patient with me.

Randy Perez
Randy Perez
5,668 Points

Well you can right click on any method or variable and hit Got to declaration(or something close to that) or you can select it and hit F3 that will take you directly to the declaration of that class, method, variable....

Randy thanks for the response I tried that and it will take me further up the same document to where the constructor is used in calling the method. But nothing that tells me hey stupid you need to look in this file over here! Any other ideas? I hate to be a bother I would just really like to know this, this exact issue is something that I have been struggling with in Java for the last month and a half.