为什么不能发现的android com.google.gson.Gson发现、android、com、Gson

2023-09-06 13:10:34 作者:万物不及你

我试图用GSON在我的项目,但我的应用程序崩溃,与logcat的话说,com.google.gson.Gson无法找到。我已经把进口com.google.gson.Gson我的类文件,我已经GSON在我的包浏览器,并通过右击将其添加 - >构建路径 - >添加库。它也显示在项目 - >属性 - > Java构建path->库选项卡 - > GSON。我做了什么错?

I'm trying to use GSON in my project, but my application is crashing, with logcat saying that com.google.gson.Gson cannot be found. I've put import com.google.gson.Gson on my class files, I have gson in my package explorer, and added it by Right click -> build path -> add libraries. It also shows up in Project->properties->java build path->libraries tab->gson. What have I done wrong?

推荐答案

什么工作对我来说:选中该复选框旁边LIB(GSON-2.0.jar)中:项目属性 - >Java构建路径 - >订单和导出选项卡。然后做一个干净的/构建。

What worked for me: Check the checkbox next to the lib (gson-2.0.jar) in: 'Project Properties' -> 'Java Build Path' -> 'Order and Export' tab. Then do a clean/build.

这增加了出口= true属性的类路径条目

This adds the exported=true attribute to the classpath entry

<classpathentry exported="true" kind="lib" path="libs/gson-2.0.jar"/>