没有用请求类型(例如,GET、POST)注释的方法 getResources 是什么意思? [英] what does Method getResources not annotated with request type (e.g., GET, POST) mean?

查看:66
本文介绍了没有用请求类型(例如,GET、POST)注释的方法 getResources 是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private interface ResourcesApi {
        @POST("/synchronize")
        void getResources(@Body Map<String, Map<String, Object>> map,
                          Callback<DataModel> callback);
    }

带有调用代码:

mApi.getResources(data, this);

该类实现了回调,因此定义了成功/失败.

The class implements Callback so success/failure are defined.

堆栈跟踪:

03-09 18:05:15.182  28570-28746/? E/AndroidRuntime﹕ FATAL EXCEPTION: pool-2-thread-1
    java.lang.IllegalStateException: Method getResources not annotated with request type (e.g., GET, POST).
            at retrofit.RestMethodInfo.parseMethodAnnotations(RestMethodInfo.java:179)
            at retrofit.RestMethodInfo.init(RestMethodInfo.java:115)
            at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:327)
            at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:262)
            at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:313)
            at retrofit.CallbackRunnable.run(CallbackRunnable.java:38)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
            at java.lang.Thread.run(Thread.java:856)

推荐答案

这意味着在运行时找不到 @POST 注释.如果没有 HTTP 方法类型(以及它包含的相对 URL),Retrofit 将无法发出请求.

It means the @POST annotation can't be found at runtime. Without the HTTP method type (and relative URL it contains), Retrofit cannot make the request.

您是否使用 Proguard 或其他工具来修剪未使用"的代码?如果是这样,请指示它保留 Retrofit 的注释.

Are you using Proguard or another tool to trim "unused" code? If so, instruct it to keep Retrofit's annotations.

这篇关于没有用请求类型(例如,GET、POST)注释的方法 getResources 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆