我正在使用 Retrofit 2.0 向我的 REST API 发出请求。我有以下工作正常的方法:
@FormUrlEncoded
@POST("/mobile_register/")
Call<MobileAuthUserJSON> createUser(@Field("username") String username, @Field("password") String password);
但是,当我像这样添加第三个字段时:
@FormUrlEncoded
@POST("/mobile_register/")
Call<MobileAuthUserJSON> createUser(@Field("username") String username, @Field("password") String password,
@Field("phone_number") String phone_num);
迎接我的是:
java.lang.NoSuchMethodError: No interface method createUser(Ljava/lang/String;Ljava/lang/String;)Lretrofit2/Call; in class Lcom/jiaohuan/jiaohuan/jsonData/UserAPI; or its super classes (declaration of 'com.jiaohuan.jiaohuan.jsonData.UserAPI' appears in /data/data/com.jiaohuan.jiaohuan/files/instant-run/dex/slice-slice_5-classes.dex)
我这辈子都弄不明白为什么会这样,这不可能是服务器的错误,因为:
1) 应用甚至在发出请求之前就崩溃了
2) 我已经设置了服务器来处理接收“phone_number”字段。
最佳答案
当我遇到此错误时,解决方案是彻底重建项目。
关于java - 在 Retrofit 2 中添加第三个 @Field 时出现 NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38297927/