简体   繁体   中英

Java jsoup type error with element vs elements

im pretty sure that my problem would be solved in <1 minute, but I don't get it... :(

import java.io.IOException;
import javax.lang.model.element.Element;
import org.jsoup.*;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class main {
public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {
        // Load website
        Document doc = Jsoup.connect("http://de.wikipedia.org/wiki/Wikipedia:Hauptseite").get();
        Elements ereignisse = doc.select("div#hauptseite-ereignisse div.inhalt ul li");
        for (Elements e : ereignisse)
            System.out.println(e.text());   
    } catch (IOException e) {
        e.printStackTrace();
    }   
}

}

Error: "Type mismatch: cannot convert from element type Element to Elements" (in "for"-signature")

My code is 90% copy-paste from an easy example and same like many questions here, but doesn't work... My problem is that I don't understand the error.

Please help

Change for (Elements e : ereignisse) to for (Element e : ereignisse) . The items in an Elements object are of type Element .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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