Error Reading From Html.class
I get this error while accessing a php script: W/System.err: Error reading from ./org/apache/harmony/awt/www/content/text/html.class The offending code snippet is as follows: URL
Solution 1:
If you're querying a PHP script, I'm pretty sure declaring a URL and then trying to get an InputStream off it isn't the right way to do it...
Try something like:
HttpClienthttpclient=newDefaultHttpClient();
HttpGethttpGet=newHttpGet("http://someurl.com");
try {
// Execute HTTP Get RequestHttpResponseresponse= httpclient.execute(httpGet);
HttpEntityentity= response.getEntity();
if (entity != null) {
InputStreaminstream= entity.getContent();
Stringresult= convertStreamToString(instream);
// Do whatever with the data here// Close the stream when you're done
instream.close();
}
}
catch(Exception e) { }
And for easily converting the stream to a string, just call this method:
privatestatic String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
Solution 2:
Why not to use HttpClient
? IMHO, it is a better way to make http calls. Check how it can be used here. Also make sure to not reinvent the wheel with reading the response from InputStream, instead use EntityUtils for that.
Post a Comment for "Error Reading From Html.class"