有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android RSS阅读器教程错误

我花了一天时间研究Android RSS阅读器

我想在我的应用程序中解析一个非常简单的XML文件http://www.sportinglife.com/rss/transfer_wire.xml

这个网站上有几个帖子回答RSS问题,比如https://stackoverflow.com/questions/1253788/simple-rss-parser-for-安卓。我已经尝试了这方面的所有解决方案,但在Eclipse中运行代码时不断出现错误

我找到了2012年4月的IBM教程,它很好地解释了代码,并在一个类文件中提供了一个解决方案http://www.ibm.com/developerworks/xml/library/x-安卓xml/index.html

我已经一步一步地学习了本教程,但是Eclipse抛出了以下错误:

[Dex Loader] Unable to execute dex: Unexpected magic: [100, 101, 120, 10, 48, 49, 51, 0]
[FootballTransfers] Conversion to Dalvik format failed: Unable to execute dex: Unexpected magic: [100, 101, 120, 10, 48, 49, 51, 0]

以前有人遇到过这个问题吗?我不知道这个错误是什么意思

当我运行https://stackoverflow.com/questions/1253788/simple-rss-parser-for-安卓线程中提供的解决方案时,我会遇到同样的错误


共 (1) 个答案

  1. # 1 楼答案

    传递inputstream而不是URL

     @Override
            protected Void doInBackground(String... urls) {
    
     arrayList = new NewsParser().getData(NewsMainActivity .this.getResources.openRawResourece(R.xml.feed));
    
                return null;
            }
    

    在getData方法中,将参数更改为InputStream

     public List<NewsBean> getData(InputStream istream) {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance()
                        .newDocumentBuilder();
    
                System.out.println("Builder : " + builder);
    
                Document doc = builder.parse(istream);
        Document doc = builder.parse(istream);
    .....
    }