诺基亚5800中的openInputStream异常

时间:2011-10-09 06:59:00

标签: java-me io inputstream

我使用以下代码从服务器解析XML。

try {
    //Open http connection
    HttpConnection httpConnection = (HttpConnection) Connector.open(URL);

    resultItem.setLabel("34");
    this.sleep(1000);
    //Initilialize XML parser
    parser = new KXmlParser();
    resultItem.setLabel("38");
    this.sleep(1000);
    resultItem.setLabel("39");
    InputStreamReader isr=new InputStreamReader(httpConnection.openInputStream());
    System.out.println("Input Sream: "+isr.read());

    resultItem.setLabel("40");
    this.sleep(1000);                
    parser.setInput(isr);

    resultItem.setLabel("42");
    this.sleep(1000);

    parser.nextTag();
    resultItem.setLabel("46");
    this.sleep(1000);

    parser.require(XmlPullParser.START_TAG, null, "login");
    resultItem.setLabel("50");
    this.sleep(1000);

    //Iterate through our XML file
    while (parser.nextTag() != XmlPullParser.END_TAG) 
    {
        readXMLData(parser);
    }
    resultItem.setLabel("57");
    this.sleep(1000);

    parser.require(XmlPullParser.END_TAG, null, "login");
    parser.next();
    resultItem.setLabel("62");
    this.sleep(1000);
    resultItem.setLabel("64");
    parser.require(XmlPullParser.END_DOCUMENT, null, null);
    resultItem.setLabel("");
    this.sleep(1000);
}
catch (Exception e) 
{
    e.printStackTrace();
    resultItem.setLabel("Error:");
    resultItem.setText( e.toString());
}

它在Nokia 2700中工作正常,但在InputStreamReader isr=new InputStreamReader(httpConnection.openInputStream());中显示IO异常。为什么会这样,我该如何解决?

1 个答案:

答案 0 :(得分:0)

您没有发送请求。让我们为什么你不能阅读请求)

试试这个:

HttpConnection httpConnection = (HttpConnection) Connector.open(URL);
rc = httpConnection.getResponseCode();
if(rc == HttpConnection.HTTP_OK) {
// all your code
}