我正在为教育目的的简单改造中的应用,并使用IntelliJ IDEA的为我的IDE。
I'm making a simple RetroFit application for educational purposes, and use IntelliJ IDEA as my IDE.
我已经正确输入了改造库(至少我认为我有),但我不能够得到GSON转换器包。我从谷歌gson.jar安装,但无处这两种库有一个名为GsonConverterFactory级,这是需要我去解析JSON。
I have imported the Retrofit library properly (at least I think I have) but I'm not able to get the Gson Converter package. I have the gson.jar from google installed but nowhere in either of these libraries is there a class called "GsonConverterFactory", which is required for me to parse JSON.
编辑:我在Windows
I'm on Windows.
推荐答案
添加编译com.squareup.retrofit:转炉GSON:2.0.0-β2
来你的的build.gradle
文件,并得到解决的依赖性或相应的jar添加到您的bulid路径。
Add compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
to your build.gradle
file and get the dependency resolved or add corresponding jars to your bulid path.
然后用 GsonConverterFactory.create()
来获得转换器厂
我试着用 2.0.0-β1
但下面给出,所以搬到 2.0它给了我工厂非法类型转换错误。 0-β2
I tried using 2.0.0-beta1
but it gave me an illegal type conversion error for factory as given below, so moved to 2.0.0-beta2
error: method addConverterFactory in class Builder cannot be applied to given types;
required: Factory
found: GsonConverterFactory
reason: actual argument GsonConverterFactory cannot be converted to Factory by method invocation conversion
所以我的建议是使用 2.0.0-β2
我的build.gradle具有以下依存关系来解决改造。
my build.gradle has following dependencies to resolve retrofit.
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
相关推荐
最新文章