gpt4 book ai didi

java - 执行期间改造异常

转载 作者:行者123 更新时间:2023-11-29 05:13:15 25 4
gpt4 key购买 nike

我是 Java 开发的新手,正在尝试学习 Retrofit api 我遇到异常有人可以帮助我吗?我已经在下面粘贴了我的代码和输出异常,请看一下谢谢,

package com.company;

import com.sun.deploy.util.SessionState;
import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Client;
import retrofit.client.Request;
import retrofit.client.Response;

import java.io.IOException;

public class Main {

public static void main(String[] args) {
// write your code here

RetrofitInterface retrofitInterface = (RetrofitInterface)new RestAdapter.Builder().setEndpoint("http://localhost:8080/new_pro").build().create(RetrofitInterface.class);
retrofitInterface.getUser(222, new Callback<String>() {
@Override
public void success(String s, Response response) {
//System.out.print(s);
}

@Override
public void failure(RetrofitError retrofitError) {

}
});
}
}

输出

Exception in thread "main" java.lang.IllegalArgumentException: RetrofitInterface.getUser: Must have return type or Callback as last argument, not both.
at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:107)
at retrofit.RestMethodInfo.parseResponseType(RestMethodInfo.java:267)
at retrofit.RestMethodInfo.<init>(RestMethodInfo.java:97)
at retrofit.RestAdapter.getMethodInfo(RestAdapter.java:213)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:236)
at com.sun.proxy.$Proxy0.getUser(Unknown Source)
at com.company.Main.main(Main.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

最佳答案

我使用的以前的界面

public interface RetrofitInterface {
// asynchronously with a callback
@GET("/")
Header getUser(@Query("user_id") int userId, Callback<Header> callback);
}

我正在使用的修改后的界面及其工作。

public interface RetrofitInterface {
// asynchronously with a callback
@GET("/")
void getUser(@Query("user_id") int userId, Callback<Header> callback);
}

关于java - 执行期间改造异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27525053/

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