Service methods cannot return void. retrofit

前端 未结 4 1677
执念已碎
执念已碎 2020-12-09 01:30

This is my method in Interface. I am calling this function but app crash with this exception:

Caused by: java.lang.IllegalArgumentException: Service m

4条回答
  •  时光说笑
    2020-12-09 02:19

    https://github.com/square/retrofit/issues/297

    Please go through this link.

    "All interface declarations will be required to return an object through which all interaction will occur. The behavior of this object will be similar to a Future and will be generic typed (T) for the success response type."

    @GET("/foo")
    Call getFoo();
    

    Based on the new Retrofit 2.0.0 beta You cannot specify return type as void to make it asynchronous

    as per the code inside retrofit (https://github.com/square/retrofit/blob/master/retrofit/src/main/java/retrofit/MethodHandler.java) it will show exception when you try the previous implementation with 2.0.0 beta

    if (returnType == void.class) {
    throw Utils.methodError(method, "Service methods cannot return void.");
    }
    

提交回复
热议问题