从错误读取html.class [英] Error reading from html.class

查看:148
本文介绍了从错误读取html.class的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个错误,同时访问一个PHP脚本:

I get this error while accessing a php script:

W/System.err: Error reading from ./org/apache/harmony/awt/www/content/text/html.class

违规的code片断如下:

The offending code snippet is as follows:

URL url = "http://server.com/path/to/script"
is = (InputStream) url.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
    sb.append(line + "\n");
}
is.close();

该错误是扔在第二行。有关该错误的谷歌搜索止跌回升0的结果。此警告并不影响我的应用程序和更多的一个烦恼的流动,而不是一个问题。它也只发生了11 API设备上(适用于API 8和罚款; 9设备)

The error is thrown on the second line. A Google search on the error turned up 0 results. This warning doesn't affect the flow of my application and its more an annoyance rather than a problem. it also only occurs on a API 11 device (works fine on API 8 & 9 devices)

推荐答案

如果你要查询一个PHP脚本,我是pretty肯定宣布一个URL,然后试图获得一个InputStream关闭它不是正确的方式做...

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...

尝试是这样的:

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://someurl.com");

try {
// Execute HTTP Get Request
HttpResponse response = httpclient.execute(httpGet);

HttpEntity entity = response.getEntity();

if (entity != null) {

    InputStream instream = entity.getContent();
    String result = 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:

private static 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();
}

这篇关于从错误读取html.class的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆