首页 / 操作系统 / Linux / Android程序 依赖库引用Gson 报java.lang.NoClassDefFoundError: com/google/gson/Gson 解决
Android 程序所依赖一个Library程序B , B 程序中用到格式化json串,转换成标准json串的要求 public static String jsonFormatter(String uglyJSONString) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(uglyJSONString);
String prettyJsonString = gson.toJson(je);
return prettyJsonString;
}但在Android程序中却报java.lang.NoClassDefFoundError: com/google/gson/Gson实际上不知道为什么 new GsonBuilder()时就是找不到该类了。。。。后来比较别人的程序发现 只有android-support-v4.jar 这个jar包是不同的。将library程序的android-support-v4.jar和Android程序的android-support-v4.jar保持一致且Android程序的java build path library 的 private library体现出依赖程序的 jar包才有效,也可能是 其中一套android-support-v4的版本太低了。。。好用的android-support-v4.jar 连接址:免费下载地址在 http://linux.linuxidc.com/用户名与密码都是www.linuxidc.com具体下载目录在 /2014年资料/8月/2/Android程序 依赖库引用Gson 报java.lang.NoClassDefFoundError下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm------------------------------------------另一篇------------------------------------------解决Android使用GSON时报错 java.lang.NoClassDefFoundError: com.google.gson.Gson在工程中导入了Gson的jar包,能正常通过编译,但执行时报错java.lang.NoClassDefFoundError: com.google.gson.Gson,查找了半天,原来是自己以导入external jar的形式引入gson的,所以编译导出的时候没有一起导出到项目中,所以执行会报找不到类定义的错误。解决方法很简单:1、右键项目 ---> properties ----> java buildpath ---> order and export2、 勾选 gson-x.x.x.jar3、保存设置,clean 项目并重新编译执行即可。Ubuntu 14.04 x64配置Android 4.4 kitkat编译环境的方法 http://www.linuxidc.com/Linux/2014-05/101148.htmUbuntu 12.04搭建Android开发环境 http://www.linuxidc.com/Linux/2012-09/69961.htmUbuntu 14.04 配置 Android SDK 开发环境 http://www.linuxidc.com/Linux/2014-05/101039.htm64位Ubuntu 11.10下Android开发环境的搭建(JDK+Eclipse+ADT+Android SDK详细) http://www.linuxidc.com/Linux/2013-06/85303.htmUbuntu 12.10 x64 安装 Android SDK http://www.linuxidc.com/Linux/2013-03/82005.htm更多Android相关信息见Android 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=11本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-08/104987.htm