2012-12-29 67 views
0

我的代码工作:java.lang.IllegalArgumentException异常与Jsoup

public static void main(String[] args) { 
    Validate.isTrue(true, "usage: supply url to fetch"); 
    try{ 
     String url="http://www.spoj.com/ranks/PRIME1/"; 
     Document doc= Jsoup.connect(url).get(); 
     Elements es=doc.getElementsByAttributeValue("class","lightrow"); 
     System.out.println(es.get(0).child(0).text()); 


    }catch(Exception e){e.printStackTrace();} 
} 

获取:

Exception in thread "main" java.lang.IllegalArgumentException: usage: supply url to fetch 
at org.jsoup.helper.Validate.isTrue(Validate.java:45) 
at org.jsoup.examples.HtmlToPlainText.main(HtmlToPlainText.java:26) 

请点我到我的错,为什么我收到了。我通过Jsoup官方网站的例子跟踪了这一点。

回答

0

它按预期运行。我认为这需要一个参数传递给程序在命令行上运行(一个URL)。

请看看这个:

public static void main(String[] args) throws IOException { 
     Validate.isTrue(args.length == 1, "usage: supply url to fetch"); 
+0

能否请你告诉它背后的原因,为什么参数计数有这样的事情呢? –

+0

如果你想运行该代码,它确实需要传递参数(这是URL)。上面的语句验证你是否通过了它。 – Swapnil

+0

同意。用一个commandlineargument运行你的代码,它的工作(我得到一个超时,但这是在这里讨论:http://stackoverflow.com/questions/14155062/jsoup-times-out-xml-gets-white-space-error-basic - 遍历页面是ti)。确保在启动之前向程序添加参数(即使从IDE运行)。 – ollo

相关问题