I wanted to use gson in my android project so I followed a tutorial and done this 我想在我的android项目中使用gson,所以我按照一个教程进行了操作
- Create a new folder, libs, in your Eclipse/Android project. 在您的Eclipse / Android项目中创建一个新文件夹libs。
- Right-click libs and choose Import -> General -> File System, then Next, Browse in the filesystem to find the library's parent directory (ie: where you downloaded it to). 右键单击库,然后选择导入->常规->文件系统,然后单击下一步,在文件系统中浏览以找到库的父目录(即:将其下载到的目录)。
- Click OK, then click the directory name (not the checkbox) in the left pane, then check the relevant JAR in the right pane. 单击“确定”,然后在左窗格中单击目录名称(而不是复选框),然后在右窗格中检查相关的JAR。 This puts the library into your project (physically). 这会将库(实际)放入您的项目中。
- Right-click on your project, choose Build Path -> Configure Build Path, then click the Libraries tab, then Add JARs..., navigate to your new JAR in the libs directory and add it. 右键单击您的项目,选择“构建路径”->“配置构建路径”,然后单击“库”选项卡,然后单击“添加JAR ...”,导航到libs目录中的新JAR并将其添加。 (This, incidentally, is the moment at which your new JAR is converted for use on Android.) (顺便说一下,这是新的JAR转换为可在Android上使用的时刻。)
it worked perfectly in android 2.2 but with android 4.0.3 it is throwing an exception 05-06 19:12:18.946: E/AndroidRuntime(602): java.lang.NoClassDefFoundError: com.google.gson.Gson 它在android 2.2中完美地工作,但是在android 4.0.3中它引发了异常05-06 19:12:18.946:E / AndroidRuntime(602):java.lang.NoClassDefFoundError:com.google.gson.Gson