0

I have compiled my program, and when I go to run it in terminal, it gives me the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup

at YelpScraper.main(YelpScraper.java:45)

Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup

at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 1 more

Here is my code:

import java.util.ArrayList;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.util.Scanner;

public class YelpScraper
{
    public static void main(String[] args) throws IOException, Exception, RuntimeException
    {        
        //Variables
        String description;
        String location;
        int pages;
        int parseCount = 0;
        Document document;

        Scanner keyboard = new Scanner(System.in);

        //Perform a Search
        System.out.print("Enter a description: ");
        description = keyboard.nextLine();

        System.out.print("Enter a state: ");
        location = keyboard.nextLine();

        System.out.print("How many pages should we scan? ");
        pages = keyboard.nextInt();

        String descString = "find_desc=" + description.replace(' ', '+') + "&";
        String locString = "find_loc=" + location.replace(' ', '+') + "&";
        int number = 0;

        String url = "https://www.yelp.com/search?" + descString + locString + "start=" + number;
        ArrayList<String> names = new ArrayList<String>();
        ArrayList<String> address = new ArrayList<String>();
        ArrayList<String> phone = new ArrayList<String>();

        //Fetch Data From Yelp
        for (int i = 0 ; i <= pages ; i++)
        {

            document = Jsoup.connect(url).get();

            Elements nameElements = document.select(".indexed-biz-name span");
            Elements addressElements = document.select(".secondary-attributes address");
            Elements phoneElements = document.select(".biz-phone");

            for (Element element : nameElements)
            {
                names.add(element.text());
            }

            for (Element element : addressElements)
            {
                address.add(element.text());
            }

            for (Element element : phoneElements)
            {
                phone.add(element.text());
            }

            for (int index = 0 ; index < 10 ; index++)
            {
                System.out.println("\nLead " + parseCount);
                System.out.println("Company Name: " + names.get(parseCount));
                System.out.println("Address: " + address.get(parseCount));
                System.out.println("Phone Number: " + phone.get(parseCount));

                parseCount = parseCount + 1;
            }

            number = number + 10;

        }
    }
}

I am using BlueJ and put my jsoup-1.10.1.jar into the library, so I'm confused as to why it suddenly can't find these classes. It compiled just fine. What am I doing wrong?

  • You don't have the JSoup jars in your classpath when you run the program and need to fix this. – Hovercraft Full Of Eels Nov 23 '16 at 19:09
  • You need to either set the classpath directly when calling your class, via the `-cp` directive or use a manifest file with your jar that gives the appropriate classpath. This is question is a duplicate a thousands times over. Please check [this link to see one way to search this site for similar questions](https://www.google.com/search?q=site%3Astackoverflow.com+java&oq=s&sourceid=chrome&ie=UTF-8#q=site:stackoverflow.com+java+ClassNotFoundException) and thereby avoid asking duplicate questions. – Hovercraft Full Of Eels Nov 23 '16 at 19:12

0 Answers0