Android java.lang.NoClassDefFoundError: org.jsoup.Jsoup

I am working with eclipse Version: Indigo Service Release 2 Build id: 20120216-1857. Android version ist 2.2. I am making an application to test the connection and analysis of a website as follows:

public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { Document doc = Jsoup.connect("http://example.com/").get(); Elements divs = doc.select("div#test"); for (Element div : divs) { System.out.println(div.text()); } } catch (Exception e) { } } } 

Manifest file:

 android:installLocation="preferExternal" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.INTERNET" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".TestActivity" android:label="@string/app_name" android:configChanges="orientation" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <uses-library android :name="org.jsoup.Jsoup" /> </activity> </application> 

I am adding the jsoup-1.6.1.jar library to the JAVA Buildpath, but I am getting a runtime error: E / AndroidRuntime (736): java.lang.NoClassDefFoundError: org.jsoup.Jsoup

How can I solve this error?

+8
java android jsoup
source share
8 answers

I ran into this exact issue after a recent update of the ADT component for Android. Android seems to ignore the build path and instead uses the default ANT options.

I solved this by removing my jar file from the build path, creating a folder in the “root” from the application hierarchy (along with src, gen, etc.) called “libs”, and put my .jar there. When cleaning / assembling and restarting the application, the error should disappear.

FYI - this is due to the fact that the JAR file does not pack into .apk files - that’s why it builds correctly, but is not available at run time on your Android device.

see NoClassDefFoundError - Eclipse and Android

+19
source share

There's also a problem that banks should be in the libs directory (with 's'), not lib .... could this be your problem?

+3
source share

You do not need a line:

  <uses-library android:name = "org.jsoup.Jsoup"/> 

in the manifest file. All you need to do to use Jsoup is to provide it part of your build path by following these steps:

  • Right click on your project and select Properties
  • Select the Java build path and select Add External JARs ...
  • Browse to jsoup jar file

Then Jsoup will act like any other library in java. For example, in my application, I use it like this:

  try { Document doc = Jsoup.connect( myHtml ).get(); Elements table = doc.select( "table#ctl00_ContentPlaceHolder1_tblPasses" ); // Returns first row of the table which we want Elements row = table.select( "tr.lightrow" ); Element record_One = row.first(); } 

Note. I did not include all my code for it because it is quite long. Anyway, after that you simply import the classes as needed, for example, in mine I use the following:

 import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; 
+2
source share
  • Right-click on the project name> Properties> tab "Java Build Path"> "Libraries" and click on the "Add External Banks" button.
  • select the jar path from your directory where you downloaded jsoup-1.7.3.jar.
  • After adding the jar, go to the next tab, Order and export, and check the box jsoup-1.7.3.jar 4 click "OK" 5.clean create your project and then run.

I solved the same problem by following these steps

+2
source share

You are doing it wrong. You cannot use Jsoup functions in oncreate Activity. You need to do either an Async task or a thread.

This prevents the execution of lock tasks in your activity.

Here is a good blog that explains how to do this, and also give sample code.

Code Example Click Here

+1
source share

I was able to solve this problem by following these steps:

  • Placing jsoup jar in the 'libs' folder (as indicated in John's answer)
  • Remove Android Dependencies and Android Private Libraries from the build path
  • Using Android Tools> Fix Project Properties to refill the above entries in the build path.
+1
source share

Just close Eclipse and open it again. The problem will be solved.

0
source share

My decision was

  • Right click on the project name> Properties> tab "Java Build Path"> "Libraries"> delete everything except "Android XX" (2.3.3 in my case) and "Android Dependencies" (according to the link found by @KarlKarlsom > android.foxykeep.com < from stack problem > stack < )
  • I created folders in my main projects. Since I used jsoup, so moved it to this folder
  • Launched eclipse, project cleanup does not work.

ps I used jsoup and sherlock. I did not change the sherlock library, only my main project.

0
source share

All Articles