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
Ryan Bend
5,951 PointsGetting JSON Data from an HTTP Request Problem, JSON Data not showing in logcat
The logcat doesn't show the data from the JSON file. I tried debugging this for almost an hour and have not idea why. The only real difference I noticed is that the filter for my app isn't in under the "All messages" tab under saved filters, it was earlier but it hasn't shown up since I booted up eclipse this last time. Help?
responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK){
InputStream inputStream = connection.getInputStream();
Reader reader = new InputStreamReader(inputStream);
int contentLength = connection.getContentLength();
char[] charArray = new char[contentLength];
reader.read(charArray);
String responseData = new String(charArray);
Log.v(TAG, responseData);
} else {
Log.i(TAG, "Unsuccessful HTTP Response Code: " + responseCode);
}
Also found this thread https://teamtreehouse.com/forum/json-does-not-show-in-logcat but it doesn't really help much.
3 Answers
Hasan Tugkan Kibar
2,230 PointsDo you have the android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE? Your code doesn't appear faulty, I have the exact same code and it works.
Ben Jakuben
Treehouse TeacherDoes anything show in the logcat tab? Either some kind of data, or the Unsuccessful HTTP Response Code message?
Rohit Sharma
4,819 PointsCheck the URL. I had "/?count=20" AND "+ NUMBER_OF_POSTS" by accident.