从android

时间:2017-11-10 05:31:48

标签: java android xml rss filenotfoundexception

RSS Feed的链接:https://news.bitcoin.com/feed/

到目前为止,这是我的代码:

MainActivity:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        RSSDataDownload downloadTask = new RSSDataDownload();
        downloadTask.execute();
    }

    public static class RSSDataDownload extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... voids) {
            //DOESN'T WORK, FILE NOT FOUND EXCEPTION:
            String MY_URL="https://news.bitcoin.com/feed" ;

                try {
                URL url = new URL(MY_URL);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();


                InputStream inputStream = connection.getInputStream();

                processXML(inputStream);

            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        }

        public void processXML(InputStream inputStream) throws Exception {
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

            DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();


           Document XMLdocument= builder.parse(inputStream);

           Element rootElement=XMLdocument.getDocumentElement(); //root element of the XML Document

            Log.d("XML",rootElement.getTagName());

        }
    }


}

以上代码适用于:http://www.bitnewz.net/rss/Feedhttp://bitcoin.worldnewsoffice.com/rss/category/1/以及其他一些RSS Feed,但不适用于https://news.bitcoin.com/feed/

有什么特殊原因吗?如何绕过它?

1 个答案:

答案 0 :(得分:0)

我不知道您面临的问题是什么,但https://news.bitcoin.com/feed/使用此库为我工作。

您可以从 RSS-Parser 库中获取想法: https://github.com/prof18/RSS-Parser