0

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

3
  • Solved it. After click on "quick solution" eclipse changed the code to "for (org.jsoup.nodes.Element e : ereignisse)", which doesnt make sence to me but works :). Thanks Commented Dec 1, 2017 at 8:39
  • @kasper2083 Please post your solution as an answer and accept it. So others can find it. In comments it will get lost. Also read How to write a good answer Commented Dec 1, 2017 at 8:41
  • @kasper2083 Use Element in For loop, in place of Elements. This will help. Check this: jsoup.org/cookbook/extracting-data/example-list-links Commented Dec 1, 2017 at 8:51

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.