Orb*_*bit 77 java android retrofit
所以Retrofit 2.0.0最近发布了,并没有真正的任何更新示例如何使用它,但我试图实现它的基本API调用.我得到了一个
java.lang.IllegalArgumentException: Unable to create converter for class` 
引起的
Caused by: java.lang.IllegalArgumentException: Could not locate converter for class orbyt.app.dataclass. Tried:
* retrofit.OkHttpBodyConverterFactory
在尝试进行api调用时.
Yac*_*Srk 128
我面临同样的问题.我修改了它:
compile 'com.squareup.retrofit2:converter-gson:<latest-version>'
到我的build.gradle
然后在创建我的Retrofit实例时指定转换器.
Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(Constants.API_BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
Aji*_*bey 15
在Retrofit 2.0中,转换器不包含在包中,当您使用Retrofit 2.0时,请确保遵循新的URL模式
基本网址:始终以/结尾
@Url:不要以/开头
Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(Constants.API_BASE_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .build();
有关2.0的更多信息,请点击此链接Retrofit 2.0:最大的更新
并且还更新build.gradle.
小智 7
相应地更改改装版本
对我来说,依赖已经存在了
compile 'com.squareup.retrofit2:retrofit:2.0.2'
对于gson 2.0.2我改变了
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
然后加
Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(Constants.API_BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
对于Retrofit V2,添加以下存储库 -
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
现在使用下面的代码 -
Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(API_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
希望它会有所帮助:)
| 归档时间: | 
 | 
| 查看次数: | 33493 次 | 
| 最近记录: |