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

Rob Schwartz
Rob Schwartz
2,934 Points

Can't use debug tool in android studio.

I am trying to use the debug tool in Android studio, I have a breakpoint set and then hit the debug option on the top toolbar but when I click on the debug tab on the bottom toolbar, I cannot step through the project at all and I do not know why,

Ben Deitch
Ben Deitch
Treehouse Teacher

Hey Rob! When you clicked debug, did the app start running? If so, did it hit your breakpoint?

Rob Schwartz
Rob Schwartz
2,934 Points

Ben, I am able to run the app and it never hits the breakpoint. I am going through the Build a weather app course, and have even taken the code from the source as given from the teacher, Ken, and it still wont enter the breakpoint. My Step-into buttons are greyed out and I can't use them, both with the given source code and with my code.

Ben Deitch
Ben Deitch
Treehouse Teacher

Hmm... I'd guess it's just not hitting the breakpoint. If you add a breakpoint to the 'super.onCreate' line in MainActivity, does that get hit?

Rob Schwartz
Rob Schwartz
2,934 Points

Yes it does hit breakpoints in the MainActivity class and all the methods except for one, which is the method that creates JSON Objects and parses for JSON data and brings it into the code.

Ben Deitch
Ben Deitch
Treehouse Teacher

Is that the 'getCurrentDetails' method? Could you share your code and point out which line is the troublemaker?

Rob Schwartz
Rob Schwartz
2,934 Points

Here is the current code:

private CurrentWeather getCurrentDetails(String jsonData) throws JSONException { JSONObject forecast = new JSONObject(jsonData);

    String timezone = forecast.getString("timezone");
    Log.v(TAG,"From JSON:"+timezone);

    JSONObject currently = forecast.getJSONObject("currently");
    *CurrentWeather currentWeather = new CurrentWeather();

    currentWeather.setHumidity(currently.getDouble("humidity"));
    currentWeather.setTimeZone(currently.getLong("time"));
    currentWeather.setIcon(currently.getString("icon"));
    currentWeather.setLocationLabel("Alcatraz Island, CA");
    currentWeather.setPrecipChance(currently.getDouble("precipProbability"));
    currentWeather.setSummary(currently.getString("summary"));
    currentWeather.setTemperature(currently.getDouble("temperature"));

    return currentWeather;
}

I am trying to put the breakpoint where the CurrentWeather object is being initialized, I have a * next to it.

Rob Schwartz
Rob Schwartz
2,934 Points

Ben, I believe I have found the issue (or at the very least an issue), but I am not sure where to go with it. To begin the program, we check to see if we are connected to the internet. This is done by calling the method "isNetworkAvailable" which returns a boolean. However, the code never seems to enter this loop. I am not sure why. Thanks for the help!