9

I am trying to use jsoup in my android studio project but i keep getting this error: Error:(10, 16) Gradle: error: package org.jsoup does not exist.

Could you guys tell me the steps on how to add jsoup library to my project? Thanks in advance.

Edit: For learning purpuse i am running the java code alone without main activity!

code:

package com.jsoupTest.jsoupTest;


import java.io.IOException;




import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.UnsupportedMimeTypeException;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

public class JsoupGetRequest {


    public static void main(String[] args) throws IOException {



        String dc=Jsoup.connect("http://somelink.com").timeout(6000).get();
        System.out.println(dc);
    }

}
user1788736
  • 2,727
  • 20
  • 66
  • 110
  • 1
    a `main`-method in an android project? This looks suspicious! Anyway, try adding this to your build.gradle `compile group: 'org.jsoup', name: 'jsoup', version: '1.9.1'` as dependency and remove `compile 'org.jsoup:jsoup:+';` from your class. ` – sschrass Jul 06 '17 at 23:22
  • 1
    Thanks for reply . I am new to android studio could you tell me how to reach build.gradle dependency section ? – user1788736 Jul 06 '17 at 23:32

2 Answers2

12

Gradle (build.gradle) in your app folder. put under dependencies section. clean and rebuild project

// jsoup HTML parser library @ https://jsoup.org/
implementation 'org.jsoup:jsoup:1.10.3'
Kwnstantinos Nikoloutsos
  • 1,832
  • 4
  • 18
  • 34
ZeroOne
  • 8,996
  • 4
  • 27
  • 45
  • That fixed the first error. I am running the java code without main activity and now i get this error:Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup at com.javagetrequest.javagetrequest.JsoupGetRequest.main(JsoupGetRequest.java:37) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) – user1788736 Jul 07 '17 at 01:21
2

You should add your dependencies in your build.gradle file. Please check the screenshot attached.

build.gradle file location on Android Studio

notGeek
  • 1,394
  • 5
  • 21
  • 40