Lostsoul
Lostsoul

Reputation: 25991

importing java libarary

I am starting to learn a few programming languages. I learned python then did a bit of jython and now want to learn java. I read a basic book but haven't done anything with importing libraries yet. I wanted to try to play around with jsoup for java(since I am familiar with beautifulsoup for python and thought it would make learning a bit easier for me).

But the example I am trying keeps failing( http://jsoup.org/cookbook/extracting-data/example-list-links ). I downloaded jsoup, copied it to libraries/java/extentions and tried the above script but I keep getting:

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.ListLinks.main(ListLinks.java:16)

At first I thought maybe the library wasn't imported right or I had to do something different to get it in netbeans but when I look at my project, I see a menu for libraries and jsoup seems to be there.

I tried a few other scripts online and am getting errors. I think I might not be importing it right, but can anyone help me identify the problem(I'm such a newbie I don't even know what to google to find the answer to this..)?

Thanks in advance!

Upvotes: 1

Views: 2219

Answers (4)

Eric V
Eric V

Reputation: 1170

Your library has been imported. If your library hasn't been imported you can't compile your java code, or in some other case you will have "ClassNotFoundException".

To Launch your program, you must supply an url...

IllegalArgumentException: usage: supply url to fetch

Upvotes: 1

no.good.at.coding
no.good.at.coding

Reputation: 20371

You're not missing any libraries - that would've given you a ClassNotFoundException instead.

You're missing the argument to the program, it expects a URL to work with:

Validate.isTrue(args.length == 1, "usage: supply url to fetch");

At this point, the input arguments to the application are being checked ensure that there is exactly one argument which is assumed to be the URL.

This blog post explains how to give arguments for your Java application in NetBeans. You ought to specify a URL (like http://www.google.com or http://stackoverflow.com) as the value there.

Upvotes: 1

Brian Roach
Brian Roach

Reputation: 76888

It's running perfectly.

The code you list (link to) has this as the first thing the program does:

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

It requires an argument to be passed into the program on the command line for it to run (an URL). And it's telling you exactly that.

Upvotes: 5

Robin Green
Robin Green

Reputation: 33033

If you see the package in a stacktrace - in fact, if your code even compiles - that means the import succeeded. The problem must be something else.

Upvotes: 3

Related Questions