在文档中选择不起作用

Selecting in document not working

我正在尝试使用 Jsoup 提取我的 html 代码中的链接,但我收到一个异常消息:

org.jsoup.nodes.Document cannot be cast to javax.swing.text.Document

而且我无法弄清楚为什么会出错,因为我已经按照网上找到的教程进行操作。

我的代码是什么样的:

    String htmlCode = Jsoup.connect(urlToDownload).get().html();
    Document doc = (Document) Jsoup.parse(htmlCode);

如有任何建议,我们将不胜感激。

此代码应该有效:

String htmlCode = Jsoup.connect(urlToDownload).get().html();
org.jsoup.nodes.Document doc = (org.jsoup.nodes.Document) Jsoup.parse(htmlCode);