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

前端 未结 8 1160
广开言路
广开言路 2020-12-01 22:12

I work with eclipse Version: Indigo Service Release 2 Build id: 20120216-1857. The Android version ist 2.2. I make an app to test a connect and parse a web site like this:

相关标签:
8条回答
  • 2020-12-01 22:21
    1. Right click on the project name > Properties > Java Build Path > tab Libraries then click on button Add External jars.
    2. select jar's path from your directory where you had downloaded jsoup-1.7.3.jar.
    3. After adding jar go to next tab Order and export and select checkbox jsoup-1.7.3.jar 4 click ok 5.clean build your project and then run.

    I solved the same problem by following above steps

    0 讨论(0)
  • 2020-12-01 22:26

    You don't need the line:

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

    in your manifest file. All you need to do to use Jsoup is to ensure it's part of your build path by doing the following:

    • Right click on your project and select Properties
    • Select Java Build Path and select Add External JARs...
    • Navigate to the Jsoup jar file

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

        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 have not included all my code for it because it's rather long. Anyway, after that you just 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;
    
    0 讨论(0)
  • 2020-12-01 22:26

    My solution was

    1. Right click on the project name > Properties > Java Build Path > tab Libraries > remove everything except the "Android X.X" (2.3.3 in my case) and the "Android Dependencies" (according to link found by @KarlKarlsom >android.foxykeep.com< from stack problem >stack<)
    2. I created folder libs in my main projects. As I was using jsoup so I moved it to this folder
    3. Restarted eclipse, clean up project didn't work

    p.s I was using jsoup and sherlock. I didn'y change sherlock library, only my main project.

    0 讨论(0)
  • 2020-12-01 22:31

    I encountered this exact problem after a recent update of the ADT component of Android. It looks like Android is ignoring the build path and instead using the ANT defaults.

    I solved this by removing my jar file from the build path, creating a folder in the "root" of the app heirarchy (alongside src, gen, etc) called "libs", and putting my .jar there. When you clean / build and re-launch the app, the error should go away.

    FYI - this is occurring because the JAR file is not getting packaged into the .apk files - this is why it builds correctly, but isn't available during run-time on your Android device.

    see NoClassDefFoundError - Eclipse and Android

    0 讨论(0)
  • 2020-12-01 22:32

    You are doing it wrong. You cant use Jsoup functions in the oncreate of Activity. You need to make either Async Task or thread.

    This is to prevent doing blocking tasks in you activity.

    Here is a nice blog that explain how to do it and provide sample code as well.

    Sample Code Click here

    0 讨论(0)
  • 2020-12-01 22:37

    There's also the issue that jars have to be in the libs (with an 's') directory and not lib....could this be your problem?

    0 讨论(0)
提交回复
热议问题