番石榴:. lang。NoClassDefFoundError,com.google.common.collect.HashBiMap

时间:2022-11-10 20:46:21

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/

我现在面临的问题是java.lang。在使用从这里下载的guava库时,可以使用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

我已经添加番石榴- 12.0。jar作为一个参考库进入我的项目,但我仍然会得到错误。你能就这个问题提些建议吗?谢谢你的帮助

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)

5 个解决方案

#1


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.

您的运行时类路径很可能不包含guava jar。为了验证这一点,请尝试在代码中打印类路径。

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

在命令行上,您可以使用:java -cp“path/to/guava”。jar”MyMainClass

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

或者,设置CLASSPATH环境变量来包含jar。

#2


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.

在我的案例中,我在我的图书馆里有guava和google收藏。谷歌图书馆与番石榴图书馆发生冲突。如果你有guava和google-collection,试着移除google-collection来重建。

#3


1  

Just download Guava library from here Guava

从这里下载Guava图书馆。

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

清洁和构建。为我工作。希望它可以帮助。干杯

#4


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.

在我的例子中,我尝试添加guav -17.0。jar与选项添加外部jar…这就是问题所在。当我移动了guav -17.0。jar在我的项目文件夹(在Libs文件下)我没有问题。

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

当然,我删除了外部JAR并使用add JAR再次添加它…选项

#5


0  

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.

我试着使用上游Guave 21和22,用sourcecompatiable jav厌恶。VERSION_1_8启用。这导致了在SDK版本24以下设备上的错误。解决方案是使用仍然支持Java 7的guave版本,该版本支持Android。

dependencies {
  compile 'com.google.guava:guava:23.3-android'
}

#1


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.

您的运行时类路径很可能不包含guava jar。为了验证这一点,请尝试在代码中打印类路径。

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

在命令行上,您可以使用:java -cp“path/to/guava”。jar”MyMainClass

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

或者,设置CLASSPATH环境变量来包含jar。

#2


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.

在我的案例中,我在我的图书馆里有guava和google收藏。谷歌图书馆与番石榴图书馆发生冲突。如果你有guava和google-collection,试着移除google-collection来重建。

#3


1  

Just download Guava library from here Guava

从这里下载Guava图书馆。

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

清洁和构建。为我工作。希望它可以帮助。干杯

#4


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.

在我的例子中,我尝试添加guav -17.0。jar与选项添加外部jar…这就是问题所在。当我移动了guav -17.0。jar在我的项目文件夹(在Libs文件下)我没有问题。

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

当然,我删除了外部JAR并使用add JAR再次添加它…选项

#5


0  

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.

我试着使用上游Guave 21和22,用sourcecompatiable jav厌恶。VERSION_1_8启用。这导致了在SDK版本24以下设备上的错误。解决方案是使用仍然支持Java 7的guave版本,该版本支持Android。

dependencies {
  compile 'com.google.guava:guava:23.3-android'
}