与org.apache.harmony.xml.ExpatParser $ ParseException的问题 [英] Problems with org.apache.harmony.xml.ExpatParser$ParseException

查看:200
本文介绍了与org.apache.harmony.xml.ExpatParser $ ParseException的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候我的SAXParser实现抛出一个

My SaxParser implementation throws sometimes a

org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: no element found

例外。在下次尝试它完美不错。 一般没有与互联网连接没有问题。

Exception. At the next attempt it works perfectly good. In general there is no problem with the internet connection.

下面是我的实现。

1)对所有的语法分析器基类

1) base class for all parser

public abstract class BaseFeedParser{

    private final URL url;
    private InputStream is;

    protected BaseFeedParser(String url) {
        try {
            this.url = new URL(url);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }

    protected InputStream getInputStream() {
        try {
            this.is = url.openConnection().getInputStream();
            return is;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    protected void closeInputStream() throws IOException{
        if(this.is!=null)
            this.is.close();
    }
}

2)一个例子解析器

2) a example parser

public class Parser extends BaseFeedParser {

    public void parse() {
        RootElement root = new RootElement("xml");
        //additional 
        Element child = root.getChild("child");
        child.setStartElementListener(new StartElementListener() {          
            @Override
            public void start(Attributes attributes) {
                // do something....
            }
        });

        try {
            Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root
                .getContentHandler());

            closeInputStream();

        } catch (Exception e) {
            throw new RuntimeException(e);
        }   
    }
}

可能是什么问题?任何建议

Any suggestions what might be the problem?

推荐答案

我已经找到了解决方案。这个问题不是XML解析器,但越野车实施NSURLConnection的的。我切换到HttpClient的,问题消失了。

I've found the solution. The problem was not the XML-Parser, but the buggy implementation of NSURLConnection. I switched to HttpClient and the problem vanished.

更多的相关信息在这里: HttpClient的在这里: <一href="http://stackoverflow.com/questions/8066738/httpurlconnection-response$c$c-is-randomly-1">HttpURLConnection响应code是随机-1

More infos here: HttpClient and here: HttpURLConnection responsecode is randomly -1

这篇关于与org.apache.harmony.xml.ExpatParser $ ParseException的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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