2

How to fix "NoClassDefFoundError"? I have been trying to setup Jsoup in my android app. I have imported the Jsoup in to libs folder. When I compile the code it compiles however, application breaks.

Here is the mainfest.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.news.scrapweb3"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk   android:minSdkVersion="14" android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.news.scrapweb3.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

Here is the code I try to show a text extracted from Jsoup to textview.

/**
     * A dummy fragment representing a section of the app, but that simply
     * displays dummy text.
     */
    public static class DummySectionFragment extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        public static final String ARG_SECTION_NUMBER = "section_number";
        private Document doc;

        public DummySectionFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main_dummy,
                    container, false);

            try{

            doc= Jsoup.connect("http://www.google.com/").get();
            String title= doc.title();
            TextView dummyTextView = (TextView) rootView
                    .findViewById(R.id.section_label);
            dummyTextView.setText(title);
            }catch(IOException e){


            }

            return rootView;
        }
    }

Here is the log cat.

03-13 09:30:24.799: W/dalvikvm(1646): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
03-13 09:30:24.809: E/AndroidRuntime(1646): FATAL EXCEPTION: main
03-13 09:30:24.809: E/AndroidRuntime(1646): java.lang.NoClassDefFoundError: org.jsoup.Jsoup
03-13 09:30:24.809: E/AndroidRuntime(1646):     at com.news.scrapweb3.MainActivity$DummySectionFragment.onCreateView(MainActivity.java:127)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.View.measure(View.java:15518)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.View.measure(View.java:15518)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.View.measure(View.java:15518)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.View.measure(View.java:15518)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.Choreographer.doFrame(Choreographer.java:532)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.os.Handler.handleCallback(Handler.java:725)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.os.Looper.loop(Looper.java:137)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at android.app.ActivityThread.main(ActivityThread.java:5041)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at java.lang.reflect.Method.invokeNative(Native Method)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at java.lang.reflect.Method.invoke(Method.java:511)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-13 09:30:24.809: E/AndroidRuntime(1646):     at dalvik.system.NativeStart.main(Native Method)

UPDATED

IF I remove this code. project start to work.

    try {

        doc = Jsoup.connect("http://www.google.com/").get();
        String title = doc.title();
        TextView dummyTextView = (TextView) rootView
                .findViewById(R.id.section_label);
        dummyTextView.setText(title);
    } catch (IOException e) {

    }             
Shaowei Ling
  • 186
  • 10
wordpressm
  • 3,189
  • 3
  • 20
  • 29

3 Answers3

2

I met this issue when I migrated project from eclispe to android studio. This solution works for me:

public class YouApplication extends Application {

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
 }
}

Since December 3rd, 2014, build tools 1.0.0-rc1 was released. Now, all you need to do is override this in your Application class:

public class YouApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
     }
    }

and modify your build.gradle like so:

 android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled true
         }
    }
    dependencies {
    compile 'com.android.support:multidex:1.0.1'}

refer: link

Community
  • 1
  • 1
huu duy
  • 2,049
  • 21
  • 31
1

Check my answer here : NoClassDefFound solution

You need to make few changes in your project through Eclipse project/properties.

Thanks.

Community
  • 1
  • 1
Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69
1

If you are using a library jar, instead of just referencing it from some other location, try dropping it in the libs folder. Worked for me a couple of times before.

Viral Patel
  • 32,418
  • 18
  • 82
  • 110