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

调用代码:

mApi.getResources(data, this);

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

堆栈跟踪:

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)
4

3 回答 3

5

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.

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

于 2014-03-10T00:54:48.343 回答
5

除了 Jake 的回答之外,这是我必须添加到我的proguard文件中才能使其正常工作的内容:

-keep class com.google.gson.** { *; }
-keep class com.google.inject.** { *; }
-keep class org.apache.http.** { *; }
-keep class org.apache.james.mime4j.** { *; }
-keep class javax.inject.** { *; }
-keep class retrofit.** { *; }
于 2014-12-22T21:15:29.487 回答
0

同意@chad 的回答,如果仍然崩溃,请添加以下行。

-keepattributes Signature
-keep class sun.misc.Unsafe { *; }
于 2016-06-24T12:10:33.800 回答