gpt4 book ai didi

java.lang.IllegalArgumentException : Unable to create call adapter for interface retrofit. 调用

转载 作者:行者123 更新时间:2023-11-30 08:43:57 30 4
gpt4 key购买 nike

我的 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)

我想知道我在代码中的错误。第二个错误原因。

谢谢。

最佳答案

我遇到了同样的问题。它在 Debug模式下工作,在 Release模式下失败。

问题是因为 pro-guard 规则。

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

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

关于java.lang.IllegalArgumentException : Unable to create call adapter for interface retrofit. 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33979694/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com