执行期间的改进异常

时间:2014-12-17 11:56:38

标签: java retrofit

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

1 个答案:

答案 0 :(得分:3)

以前的界面我正在使用

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);
}