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

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

I can't throws Exception and IOException in Java

问题

  1. import org.jsoup.Jsoup;
  2. import org.jsoup.nodes.Document;
  3. import org.jsoup.nodes.Element;
  4. import org.jsoup.select.Elements;
  5. import java.io.IOException;
  6. public class JsoupTest {
  7. public static void main(String[] args) throws IOException {
  8. final Document document = Jsoup.connect("http://en.wikipedia.org/").get();
  9. final Elements newsHeadLines = document.select("#mp-itn b a");
  10. for(Element headline : newsHeadLines) {
  11. System.out.println(headline);
  12. }
  13. }
  14. }

  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.

  1. import org.jsoup.Jsoup;
  2. import org.jsoup.nodes.Document;
  3. import org.jsoup.nodes.Element;
  4. import org.jsoup.select.Elements;
  5. import java.io.IOException; > It throws error: Cannot resolve symbol 'java' - Add Maven dependency
  6. public class JsoupTest {
  7. public static void main(String[] args) throws IOException { > Cannot resolve symbol 'IOException'
  8. // download the HTML from wikipedia and parses it
  9. final Document document = Jsoup.connect("http://en.wikipedia.org/").get();
  10. // Select a bunch of a tags
  11. final Elements newsHeadLines = document.select("#mp-itn b a");
  12. // Prints to console
  13. for(Element headline : newsHeadLines) { > foreach not applicable to type 'org.jsoup.select.Elements'
  14. System.out.println(headline); > Cannot resolve symbol 'System'
  15. }
  16. }
  17. }

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:

确定