英文:
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);
}
}
}
- 我在哪里找到这个依赖?
- 我该如何查找依赖?因为我已经在 Maven 仓库中查找过,但没有找到。
- 即使对于上面我展示的
System.out.println
方法,编译器也报错,为什么会这样? - 编译器报错了,我在下面展示了,错误信息为
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:
- Where did you find this that dependency?
- How can I find dependencies, because I checked Maven repository but I couldn't find.
- Compiler throws error even for System.out.println method as I showed above, why is that?
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论