[英]Jsoup - The method connect(String) is undefined for the type Jsoup
So I'm trying to install Jsoup to Eclipse.所以我正在尝试将 Jsoup 安装到 Eclipse。
So i tried to run the example they gave on their website (see code) I could import Document and Elements.所以我试图运行他们在他们的网站上给出的例子(见代码)我可以导入文档和元素。 But it keeps giving an error on "connect".
但它一直在“连接”上出错。 Am i doing something wrong??
难道我做错了什么?? Does anyone know how to fix this problem?
有谁知道如何解决这个问题?
Error:错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method connect(String) is undefined for the type Jsoup
at JsoupTesting.Jsoup.main(Jsoup.java:12)
Jsoup test: Jsoup测试:
package JsoupTesting;
import java.io.IOException;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class Jsoup {
public static void main(String[] args) {
Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
Elements newsHeadlines = doc.select("#mp-itn b a");
}
}
Problem is that your class is also named Jsoup
so compiler in this code问题是你的类也被命名为
Jsoup
所以在这段代码中编译器
Jsoup.connect("http://en.wikipedia.org/")
tries to use connect(String)
method from your class, not from org.jsoup.Jsoup
class, and since there is no such method in your class you see the error.尝试使用您的类中的
connect(String)
方法,而不是org.jsoup.Jsoup
类,并且由于您的类中没有这样的方法,因此您会看到错误。 To remove this problem change name of your class to something else like要消除此问题,请将您的班级名称更改为其他名称
public class JsoupDemo {
...
}
and add import to org.jsoup.Jsoup
which has method you want to invoke.并将导入添加到
org.jsoup.Jsoup
,其中包含您要调用的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.