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 trialkyle rebstock
2,019 Pointserror: cannot find symbol reader.read(charArray);
I followed the instructions line by line and even tried looking into the documentation, then looked in the forums.
I get this error on the last part of the code challenge. I have tried an uppercase Reader.read and a lowercase reader.read.
error: cannot find symbol reader.read(charArray);
here is my code
String responseData = "";
try { URL treehouseUrl = new URL("http://blog.teamtreehouse.com/api/get_recent_summary/?count=20"); HttpURLConnection connection = (HttpURLConnection) treehouseUrl.openConnection(); connection.connect(); int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
// Code to read InputStream goes here!
InputStream inputStream = connection.getInputStream();
Reader read = new InputStreamReader(inputStream);
int contentLength = connection.getContentLength();
char[] charArray = new char[contentLength];
Reader.read(charArray);
}
} catch (MalformedURLException e) { Log.e(TAG, "MalformedURLException caught!", e); } catch (IOException e) { Log.e(TAG, "IOException caught!", e); }
1 Answer
Jaroslav Vankat
12,054 PointsThis code works for me:
String responseData = "";
try {
URL treehouseUrl = new URL("http://blog.teamtreehouse.com/api/get_recent_summary/?count=20");
HttpURLConnection connection = (HttpURLConnection) treehouseUrl.openConnection();
connection.connect();
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
// Code to read InputStream goes here!
InputStream inputStream = connection.getInputStream();
Reader reader = new InputStreamReader(inputStream);
char[] charArray = new char[connection.getContentLength()];
reader.read(charArray);
}
}
catch (MalformedURLException e) {
Log.e(TAG, "MalformedURLException caught!", e);
}
catch (IOException e) {
Log.e(TAG, "IOException caught!", e);
}
In the very last part you just have to add this line to the code:
responseData = new String(charArray);
kyle rebstock
2,019 Pointskyle rebstock
2,019 PointsAh I found my problem was that I was trying a syntax like Class.read when it should have been lowercase as in the reader object I created then .read.
So if I created a Reader object named asdf:
Reader asdf = new InputStreamReader(intputStream);
Then later I would call asdf.read(charArray);
Such a simple mistake haha.
Thanks so much to you.