【问题标题】:io exception in openInputStream in Nokia 5800诺基亚 5800 中 openInputStream 中的 io 异常
【发布时间】:2011-12-03 20:30:41
【问题描述】:

我正在使用以下代码从服务器解析 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 异常。为什么会发生这种情况,我该如何解决?

【问题讨论】:

  • 异常的详细信息是什么。还有其他消息吗?
  • 我可以知道在很多地方使用this.sleep(1000)的原因吗?
  • 我正在检查设备出现问题的确切位置。这就是我使用 this.sleep(1000) 并将值设置为 stringItem 的原因。

标签: java-me io inputstream


【解决方案1】:

您没有发送请求。这就是为什么你不能阅读请求)

试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多