Guava: java.lang.NoClassDefFoundError - com.google.common.collect.HashBiMap
Asked Answered
D

5

9

I currently face the problem of java.lang.NoClassDefFoundError: com.google.common.collect.HashBiMap when using guava libraries downloaded from here: http://code.google.com/p/guava-libraries/

I already add guava-12.0.jar into my project as a reference library but I still get the error. May you give some advice on what the problem would be? Thankyou for your help

package my.project;

import android.app.Activity;
import android.os.Bundle;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;

public class MainActivity extends Activity{

     private BiMap<String,String>  bidiMap; 

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
          setContentView(R.layout.bible_help_cal);

        bidiMap = HashBiMap.create();           
        bidiMap.put("a","100");
        bidiMap.put("b","200");


    }


}

Error Message I get

05-29 18:35:19.737: E/AndroidRuntime(376): FATAL EXCEPTION: main
05-29 18:35:19.737: E/AndroidRuntime(376): java.lang.NoClassDefFoundError: com.google.common.collect.HashBiMap
05-29 18:35:19.737: E/AndroidRuntime(376):  at my.project.MainActivity.onCreate(MainActivity.java:18)
05-29 18:35:19.737: E/AndroidRuntime(376):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
05-29 18:35:19.737: E/AndroidRuntime(376):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
05-29 18:35:19.737: E/AndroidRuntime(376):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
05-29 18:35:19.737: E/AndroidRuntime(376):  at android.app.ActivityThread.access$1500(ActivityThread.java:122)
05-29 18:35:19.737: E/AndroidRuntime(376):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
05-29 18:35:19.737: E/AndroidRuntime(376):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-29 18:35:19.737: E/AndroidRuntime(376):  at android.os.Looper.loop(Looper.java:132)
05-29 18:35:19.737: E/AndroidRuntime(376):  at android.app.ActivityThread.main(ActivityThread.java:4025)
05-29 18:35:19.737: E/AndroidRuntime(376):  at java.lang.reflect.Method.invokeNative(Native Method)
05-29 18:35:19.737: E/AndroidRuntime(376):  at java.lang.reflect.Method.invoke(Method.java:491)
05-29 18:35:19.737: E/AndroidRuntime(376):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-29 18:35:19.737: E/AndroidRuntime(376):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-29 18:35:19.737: E/AndroidRuntime(376):  at dalvik.system.NativeStart.main(Native Method)
Divisor answered 29/5, 2012 at 18:45 Comment(0)
W
12

This error means that the class was available at compile time, but cannot be found during run time. It most commonly happens when your compile time classpath is different from your runtime classpath.

It is very likely that your runtime classpath doesn't contain the guava jar. To verify this, try printing your classpath in your code.

on the command line, you can use: java -cp "path/to/guava.jar" MyMainClass

or alternatively, set the CLASSPATH environment variable to include the jar.

Westley answered 29/5, 2012 at 18:49 Comment(4)
Thanks for your quick response. So how can I put the guava jar into my runtime classpath??Divisor
An adroid project, In eclipseDivisor
check your "run configurations". make sure the guava jar is included. it should already be included if you are building with eclipse, but maybe for some reason it is not.Westley
Thanks for your idea.I solve the problem by copying the jar file to lib folder and the problem is goneDivisor
P
5

I was trying to use upstream Guave 21 and 22, with sourceCompatibility JavaVersion.VERSION_1_8 enabled. This caused this error on devices below SDK version 24. The solution was to use a guave version that still supports Java 7, which was backported for Android.

dependencies {
  compile 'com.google.guava:guava:23.3-android'
}
Pepsin answered 2/4, 2018 at 21:35 Comment(0)
K
2

In my case, I had both guava and google-collection in my library. google-collection library was conflicting with guava library. If you have both guava and google-collection, try to remove google-collection to rebuild.

Kelantan answered 25/4, 2014 at 16:13 Comment(0)
W
1

Just download Guava library from here Guava

Clean and Build. Works for me. Hope it Helps. Cheers

Walking answered 19/11, 2015 at 7:1 Comment(0)
F
0

In my case, I tried to add the guava-17.0.jar with the option Add External JARs... and this was the problem. When I moved the guava-17.0.jar in my projects folder (under the Libs file) I had no problem.

Of course I, removed the External JAR and add it again using the Add JARs... option

Florenceflorencia answered 17/7, 2014 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.