我不能在Java中抛出异常和IOException。

huangapple go评论69阅读模式
英文:

I can't throws Exception and IOException in Java

问题

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;

public class JsoupTest {
    public static void main(String[] args) throws IOException {
        final Document document = Jsoup.connect("http://en.wikipedia.org/").get();
        final Elements newsHeadLines = document.select("#mp-itn b a");

        for(Element headline : newsHeadLines) {
            System.out.println(headline);
        }
    }
}

  1. 我在哪里找到这个依赖?
  2. 我该如何查找依赖?因为我已经在 Maven 仓库中查找过,但没有找到。
  3. 即使对于上面我展示的 System.out.println 方法,编译器也报错,为什么会这样?
  4. 编译器报错了,我在下面展示了,错误信息为 foreach not applicable to type 'org.jsoup.select.Elements',为什么会出现这种情况?

感谢您提供的所有答案。我不想直接获得依赖项,我想知道其中的原因。谢谢。

英文:

I can't throws Exceptions such as IOException and Exception. I need to add dependencies of these but I couldn't find it.

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;  > It throws error: Cannot resolve symbol 'java' - Add Maven dependency

public class JsoupTest {
    public static void main(String[] args) throws IOException {  > Cannot resolve symbol 'IOException' 
        // download the HTML from wikipedia and parses it
        final Document document = Jsoup.connect("http://en.wikipedia.org/").get();
        // Select a bunch of a tags
        final Elements newsHeadLines = document.select("#mp-itn b a");
        // Prints to console

        for(Element headline : newsHeadLines) {  > foreach not applicable to type 'org.jsoup.select.Elements'
            System.out.println(headline);  > Cannot resolve symbol 'System'
        }
    }
}

My question can be basic but I'm pretty new on this sorry. If you give my answer please add these:

  1. Where did you find this that dependency?
  2. How can I find dependencies, because I checked Maven repository but I couldn't find.
  3. Compiler throws error even for System.out.println method as I showed above, why is that?
  4. Compiler throws error which I showed on belove, foreach not applicable to type 'org.jsoup.select.Elements'

Thank you for your all answers. I don't want directly dependency. I want it to know why. Thanks

答案1

得分: 0

你不需要添加依赖项来使用 IOException 或者 System

你可能没有正确使用编译器,或者你的集成开发环境显示了不存在的错误。

英文:

You do not need to add a dependency to use IOException or System.

You probably did not use the compiler correctly or your IDE shows non-existent errors.

huangapple
  • 本文由 发表于 2020年10月6日 00:57:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/64213048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定