android – Guava:java.lang.NoClassDefFoundError – com.google.common.collect.HashBiMap

前端之家收集整理的这篇文章主要介绍了android – Guava:java.lang.NoClassDefFoundError – com.google.common.collect.HashBiMap前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我使用从这里下载的guava库时,我目前面临 java.lang.NoClassDefFoundError:com.google.common.collect.HashBiMap的问题:
http://code.google.com/p/guava-libraries/

我已经将guava-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");


    }


}

我得到的错误消息

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)

解决方法

错误表示该类在编译时可用,但在运行时无法找到.当编译时类路径与运行时类路径不同时,最常发生这种情况.

您的运行时类路径很可能不包含番石榴罐.要验证这一点,请在代码中尝试printing your classpath.

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

或者,设置CLASSPATH环境变量以包含jar.

猜你在找的Android相关文章