So I'm trying to install Jsoup to 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:
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.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. 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.