java.lang.IllegalArgumentException:无法为方法UserApi.verifyUser的com.dlv.dlv.UserResponseInfo类创建转换器

时间:2019-02-23 09:01:16

标签: android

我正在使用aurae / retrofit-logansquare来解析我的android改造项目中的json。 我遇到以下错误

  

E / Android运行时:致命异常:主要                     流程:com.dlv.dlv,PID:5922                     java.lang.IllegalArgumentException:无法为com.dlv.dlv.UserResponseInfo类创建转换器                         对于方法UserApi.verifyUser                         在retrofit2.ServiceMethod $ Builder.methodError(ServiceMethod.java:720)                         在retrofit2.ServiceMethod $ Builder.createResponseConverter(ServiceMethod.java:706)                         在retrofit2.ServiceMethod $ Builder.build(ServiceMethod.java:167)                         在retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)                         在retrofit2.Retrofit $ 1.invoke(Retrofit.java:145)                         在java.lang.reflect.Proxy.invoke(Proxy.java:813)                         位于$ Proxy0.verifyUser(未知来源)                         在com.dlv.dlv.RestApi.verifyUser(RestApi.java:156)                         在com.dlv.dlv.DlvActivity $ 1.onClick(DlvActivity.java:52)                         在android.view.View.performClick(View.java:5610)                         在android.view.View $ PerformClick.run(View.java:22265)                         在android.os.Handler.handleCallback(Handler.java:751)                         在android.os.Handler.dispatchMessage(Handler.java:95)                         在android.os.Looper.loop(Looper.java:154)                         在android.app.ActivityThread.main(ActivityThread.java:6077)                         在java.lang.reflect.Method.invoke(本机方法)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)                      原因:java.lang.IllegalArgumentException:无法找到类的ResponseBody转换器   com.dlv.dlv.UserResponseInfo。                       尝试过:                        * retrofit2.BuiltInConverters                        * com.github.aurae.retrofit2.LoganSquareConverterFactory                         在retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:346)                         在retrofit2.Retrofit.responseBodyConverter(Retrofit.java:308)                         在retrofit2.ServiceMethod $ Builder.createResponseConverter(ServiceMethod.java:704)                             ...还有16个

应用程序终止。

构建gradle(module:app)
compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.bluelinelabs:logansquare:1.3.6' compile 'com.github.aurae.retrofit2:converter-logansquare:1.4.1'

3 个答案:

答案 0 :(得分:0)

坠机的实际原因

java.lang.IllegalArgumentException: Could not locate ResponseBody converter for class com.dlv.dlv.UserResponseInfo

更改此

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.bluelinelabs:logansquare:1.3.6'
compile 'com.github.aurae.retrofit2:converter-logansquare:1.4.1'

implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.bluelinelabs:logansquare:1.3.6'
implementation 'com.github.aurae.retrofit2:converter-logansquare:1.4.1'

您的改造实例:

Retrofit retrofit = new Retrofit.Builder()
.baseUrl("BASE_URL")
.addConverterFactory(LoganSquareConverterFactory.create())
.build();

答案 1 :(得分:0)

一个原因可能是您在@SerializedName()中使用了相同的名称用于多个字段。

答案 2 :(得分:0)

是的,这是因为有时我们会使用已经存在的字段对文件进行序列化

 `@SerializedName("user_name")
    @Expose
    private String avartar;`

而且我已经有了私有字符串用户名;