Runnable Jsoup.connect

时间:2014-04-13 15:12:56

标签: java android

当我用烤面包开始这个Rannable时 - 它有效! 但是当我试图通过Jsoup.connect获取文件时,它会破坏应用并显示错误:

04-13 14:45:09.695: E/AndroidRuntime(1634): FATAL EXCEPTION: main
04-13 14:45:09.695: E/AndroidRuntime(1634): android.os.NetworkOnMainThreadException
04-13 14:45:09.695: E/AndroidRuntime(1634):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084)
04-13 14:45:09.695: E/AndroidRuntime(1634):     at libcore.io.IoBridge.recvfrom(IoBridge.java:503)
04-13 14:45:09.695: E/AndroidRuntime(1634):     at libcore.net.http.HttpConnection.isStale(HttpConnection.java:256)
04-13 14:45:09.695: E/AndroidRuntime(1634):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:71)


Runnable prs = new Runnable() {
    public void run() {
        Document doc = null;
        try {
            doc = Jsoup.connect("http://play.radio.com/").get();

        } catch (IOException e) {

            e.printStackTrace();
        }
        parser.postDelayed(prs, 10000);
    }
};

我也不能使用AsyncTask,因为 我应该每隔10秒启动一次这段代码并解析页面。我无法运行AsyncTask两次!

怎么办?

0 个答案:

没有答案