-1

So I'm writting a code I got from a post here and it uses jsoup.. I'm also USING A MACBOOK PRO version 10.11.3 and my java is up to date.

The code is

package com.stackoverflow.q2835505;

import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.select.*;

public class Test {

public static void main(String[] args) throws Exception {
    String url = "http://stackoverflow.com/questions/2835505";
    Document document = Jsoup.connect(url).get();

    String question = document.select("#question .post-text").text();
    System.out.println("Question: " + question);

    Elements answerers = document.select("#answers .user-details a");
    for (Element answerer : answerers) {
        System.out.println("Answerer: " + answerer.text());
    }
}

}

THE PROBLEM I'm having is that I get the compile errors:

Jack-MacBook-Pro:desktop iModelEx$ javac Test.java
Test.java:3: error: package org.jsoup does not exist
import org.jsoup.*;
^
Test.java:4: error: package org.jsoup.nodes does not exist
import org.jsoup.nodes.*;
^
Test.java:5: error: package org.jsoup.select does not exist
import org.jsoup.select.*;
^
Test.java:11: error: cannot find symbol
        Document document = Jsoup.connect(url).get();
        ^
  symbol:   class Document
  location: class Test
Test.java:11: error: cannot find symbol
        Document document = Jsoup.connect(url).get();
                        ^
  symbol:   variable Jsoup
  location: class Test
Test.java:16: error: cannot find symbol
        Elements answerers = document.select("#answers .user-details a");
        ^
  symbol:   class Elements
  location: class Test
Test.java:17: error: cannot find symbol
        for (Element answerer : answerers) {
             ^
  symbol:   class Element
  location: class Test
7 errors

So that being said, I downloaded jsoup-1.10.1.jar but I don't know if I should leave it on the desktop or put it into a folder? Or open it somehow? What should I do? Thanks a lot!

EDIT: This is a specific problem with Jsoup and not my code, since all the errors point to jsoup files which apparently aren't implemented properly in my java library

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
JanCamila
  • 1
  • 1
  • 1
    Possible duplicate of [What does a "Cannot find symbol" compilation error mean?](http://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) – Pradeep Simha Dec 05 '16 at 06:35
  • Nope, this is jsoup specific, my java works fine its just this one library :( – JanCamila Dec 05 '16 at 06:41
  • No please read above link, it means your jsoup jar is not available in classpath! – Pradeep Simha Dec 05 '16 at 06:42
  • Oh really! Ok I will read it :D – JanCamila Dec 05 '16 at 06:45
  • Ok still don't get it. I'm doing everything right. The only problem is that my import jsoup is not importing the files. Can someone tell me what I can do to fix this? I have spent the past 2 hours tryign to figure this out – JanCamila Dec 05 '16 at 06:48

1 Answers1

1

You have to download jsoup.

After downloading jsoup go to your project properties->java build path->libraries->add external jar

And then find your jsoup.jar that you just downloaded.

bhazero025
  • 337
  • 4
  • 15
  • Ok but how do I access project properties? Like I don't even know where to click this is java for beginners for me – JanCamila Dec 05 '16 at 06:57
  • There are two ways to do that. – bhazero025 Dec 05 '16 at 06:58
  • On the top of your screen there is a tab saying project, and under that tab there is a project properties. Also if you right click your project on the left side of your screen it will show your project properties. I can send you a screenshot if you are still having problems. – bhazero025 Dec 05 '16 at 06:59
  • Hmm I think I'm forgetting to tell you I'm coding in a txt file. So I literary have no project button anywhere on my screen. I'm on a macbook pro – JanCamila Dec 05 '16 at 07:00
  • I would recommend you to download eclipse. – bhazero025 Dec 05 '16 at 07:01
  • Or alternative to Eclipse, NetBeans or IntelliJ IDEs. – Basil Bourque Dec 05 '16 at 08:42