简体   繁体   English

Jsoup - 未定义 Jsoup 类型的 connect(String) 方法

[英]Jsoup - The method connect(String) is undefined for the type Jsoup

So I'm trying to install Jsoup to Eclipse.所以我正在尝试将 Jsoup 安装到 Eclipse。

  1. Made a user library (Window->Preferences, Java->build path->user library, new->name("JsoupLibrary")->add JARs) the JARs.制作了一个用户库(Window->Preferences,Java->build path->user library,new->name("JsoupLibrary")->add JARs)JARs。 The JARs I downloaded from http://jsoup.org/download我从http://jsoup.org/download下载的 JAR
  2. Build the path to my project.构建我的项目的路径。 (right click project->build path->configure build path, add library->user library->next->JsoupLibrary-finish) (右键项目->构建路径->配置构建路径,添加库->用户库->下一步->JsoupLibrary-finish)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM