java.lang.IllegalArgumentException:无法为接口retrofit.Call创建调用适配器

时间:2015-11-29 05:24:33

标签: java android retrofit

我的 VSApiEndpointInterface

中的代码
@POST(REGISTER_USER)
Call registerUser(@Body User user);

用户类如下所示。

public class User {
    String email;
    String password;

    public User(String email, String password) {
        this.email = email;
        this.password = password;
    }
}

在主Activity中,我创建了用户对象,

User user = new User("hello_new_user@gmail.com", "123456");


Call call = apiService.registerUser(user);
                call.enqueue(new Callback<User>() {
                    @Override
                    public void onResponse(Response<User> response, Retrofit retrofit) {
                        int statusCode = response.code();
                        System.out.print("Veer " +response.body());
                    }

                    @Override
                    public void onFailure(Throwable t) {
                        // Log error here since request failed
                    }
                });

我也试过了,

Call<User> registerUser(@Body User user);

但同样的错误。

全程

   11-29 10:12:59.299 28854-28854/com.myapp.app W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41017258)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: FATAL EXCEPTION: main
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: java.lang.IllegalArgumentException: Unable to create call adapter for interface retrofit.Call
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     for method VSApiEndpointInterface.registerUser
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.Utils.methodError(Utils.java:177)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.MethodHandler.createCallAdapter(MethodHandler.java:47)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.MethodHandler.create(MethodHandler.java:26)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.Retrofit.loadMethodHandler(Retrofit.java:151)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.Retrofit$1.invoke(Retrofit.java:132)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at $Proxy0.registerUser(Native Method)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at com.myapp.app.activity.LoginActivity$1.onClick(LoginActivity.java:48)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.view.View.performClick(View.java:3517)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:14155)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:605)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:92)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:4508)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:  Caused by: java.lang.IllegalArgumentException: Call return type must be parameterized as Call<Foo> or Call<? extends Foo>
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.Utils.getCallResponseType(Utils.java:185)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.ExecutorCallAdapterFactory.get(ExecutorCallAdapterFactory.java:35)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.Retrofit.nextCallAdapter(Retrofit.java:189)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.Retrofit.callAdapter(Retrofit.java:175)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.MethodHandler.createCallAdapter(MethodHandler.java:45)
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.MethodHandler.create(MethodHandler.java:26) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.Retrofit.loadMethodHandler(Retrofit.java:151) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at retrofit.Retrofit$1.invoke(Retrofit.java:132) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at $Proxy0.registerUser(Native Method) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at com.myapp.app.activity.LoginActivity$1.onClick(LoginActivity.java:48) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.view.View.performClick(View.java:3517) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:14155) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:605) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:92) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:4508) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) 
    11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 

我想知道我在代码中的错误。其次是错误的原因。

感谢。

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。它在调试模式下工作,并且在发布模式下失败。

问题在于亲保护规则。

这对我有所帮助 https://github.com/krschultz/android-proguard-snippets/tree/master/libraries

这里的改造和Okio规则对我有用。