Android Eclipse 错误:“Gson 无法解析为类型”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3080454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Eclipse Error: "Gson cannot be resolved to a type"
提问by mattmcmanus
I'm relatively new to Java, eclipse and android so this could be a completely silly question, but I'm going to ask it none the less.
我对 Java、eclipse 和 android 比较陌生,所以这可能是一个完全愚蠢的问题,但我仍然会问它。
I've got a project I'm learning with to test connecting to the flickr api and simply displaying recent images. I'm at the point now where I want to parse the JSON received from flickr. I've downloaded gson 1.4 and added the zip to the java build path through "add external jars." It's successfully loaded and I can see google-gson under referenced libraries in the package explorer. My problem is, when I try to use it, I simply get an error.
我有一个正在学习的项目,用于测试连接到 flickr api 并仅显示最近的图像。我现在想解析从 flickr 收到的 JSON。我已经下载了 gson 1.4 并通过“添加外部 jars”将 zip 添加到 java 构建路径。它已成功加载,我可以在包资源管理器中的引用库下看到 google-gson。我的问题是,当我尝试使用它时,我只是收到一个错误。
Gson gson = new Gson();
Gson gson = new Gson();
It highlights Gson and says that "Gson cannot be resolved to a type." What am I missing here? It worked once and has since stopped. I've tried removing the jars, cleaning the project and re-adding the jars but it still doesn't work.
它突出显示了 Gson 并说“Gson 无法解析为类型”。我在这里错过了什么?它工作过一次,后来停止了。我试过删除罐子,清理项目并重新添加罐子,但它仍然不起作用。
Am I just completely noobing this up or is there another problem?
我只是完全不同意这个还是有其他问题?
回答by mattmcmanus
I'm not sure exactly why this worked but I extracted the zip and just added gson-1-4.jar and it appears to have worked.
我不确定这到底为什么起作用,但我提取了 zip 并添加了 gson-1-4.jar 并且它似乎起作用了。
Hooray!
万岁!
回答by Mudit Jain
Same problem occurred with me too. The solution is to download the entire gson package ie. google-gson-1.6-release.zip instead of stream only version ie google-gson-stream-1.6.jar. It works fine after you unzip the package and add the jars in your build path.
同样的问题也发生在我身上。解决方案是下载整个 gson 包,即。google-gson-1.6-release.zip 而不是仅流版本,即 google-gson-stream-1.6.jar。解压缩包并在构建路径中添加 jar 后,它工作正常。
Cheers Mudit
干杯穆迪特