Jump to content

Java - Cannot Resolve Symbol

McMitch
Go to solution Solved by Philosobyte,

I think the problem is it needs to be

 

new Jsoup().connect("blahblah")

 

 

You're missing the parentheses before the .connect

So I'm using IntelliJ and it seems like a simple problem but all of the onlinet resources haven't fixed my problem.

 

I have this code:

package WorldBoss;import org.jsoup.Jsoup;import org.jsoup.nodes.*;public class WorldBoss {public static void main(String [] args) {Document page = new Jsoup.connect("http://wiki.guildwars2.com/wiki/World_boss").get();Element link = page.select("span").first();System.out.println(link);}}

But I get an error on the connect part of Jsoup.connect saying "Cannot resolve symbol 'connect'"

I have imported the library following this page http://goo.gl/bdAQPt

 

My project structure is like this:

703a69e1cb.png

What am I doing wrong?

Any help is greatly appreciated.

Thanks

#MakeBombs                                       3x3x3 Time: 15.76s

Link to comment
Share on other sites

Link to post
Share on other sites

This is why I don't use java, unless your doing android apps java is trash.

 

That said, there's another problem which would only manifest when you got it run: you're passing the URL in flavor of a java.lang.String instead of a java.net.URL. A String would be treated as plain HTML, not as a resource. Fix it as well:

URL url = new URL("http://www.apple.com/pr/");
Document document = Jsoup.parse(url, 3000);

 

you just need to ensure that Jsoup libraries are present in both the compiletime and runtime classpath. When using javac.exe and java.exe, use the -cp argument. E.g. to compile it:

javac -cp .;/path/to/jsoup.jar com/example/YourClass.java

and to execute it:

java -cp .;/path/to/jsoup.jar com.example.YourClass

 

got this from whitephoenix's link

https://linustechtips.com/main/topic/631048-psu-tier-list-updated/ Tier Breakdown (My understanding)--1 Godly, 2 Great, 3 Good, 4 Average, 5 Meh, 6 Bad, 7 Awful

 

Link to comment
Share on other sites

Link to post
Share on other sites

Do I need to add that to my settings somewhere? Typing it into the console gives this.

54f0057da9.png

I get what seems to be the same error :/

 

Did I do it wrong?

#MakeBombs                                       3x3x3 Time: 15.76s

Link to comment
Share on other sites

Link to post
Share on other sites

I think the problem is it needs to be

 

new Jsoup().connect("blahblah")

 

 

You're missing the parentheses before the .connect

Link to comment
Share on other sites

Link to post
Share on other sites

I think the problem is it needs to be

 

new Jsoup().connect("blahblah")

 

 

You're missing the parentheses before the .connect

This solved it, but after surrounding it with a try catch that disappeared, but it worked.

 

Thanks!

#MakeBombs                                       3x3x3 Time: 15.76s

Link to comment
Share on other sites

Link to post
Share on other sites

This solved it, but after surrounding it with a try catch that disappeared, but it worked.

 

Thanks!

No problem, the concept behind it (which I didn't explain earlier because I was in a rush) is that when you only use Jsoup instead of Jsoup(), you're not actually creating a new object because you're not calling the constructor; the compiler thinks you're trying to call a static inner class. 

 

That's why you always have to use 

 

new String();

new ArrayList<>();

 

instead of 

 

new String;

new ArrayList<>;

 

Without the parentheses, you're calling the class, not the constructor. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×