【问题标题】:error: elements in annotation type declarations cannot declare formal parameters错误:注释类型声明中的元素不能声明形参
【发布时间】:2018-08-16 12:50:30
【问题描述】:

我是 android 开发的业余爱好者。我正在尝试在我的 android 项目中使用改造和 rxjava 将数据发布/发送到服务器。我在关注这个link

但在代码的接口部分,我得到 2 个编译器错误,代码无法编译。

error: elements in annotation type declarations cannot declare formal parameters
error: invalid type for element {0} of annotation type

界面看起来像给定的链接。不过,我只是发布它。

public @interface APIService {

@POST("/posts")
@FormUrlEncoded
Observable<Post> savePost(@Field("title") String title,
                             @Field("body") String body,
                             @Field("userId") long userId);
}

我这样称呼它:

mAPIService.savePost(title, body,1).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())

在哪里private APIService mAPIService;

帖子模型如下:

public class Post {

@SerializedName("title")
@Expose
private String title;
@SerializedName("body")
@Expose
private String body;
@SerializedName("userId")
@Expose
private Integer userId;
@SerializedName("id")
@Expose
private Integer id;

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getBody() {
    return body;
}

public void setBody(String body) {
    this.body = body;
}

public Integer getUserId() {
    return userId;
}

public void setUserId(Integer userId) {
    this.userId = userId;
}

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

@Override
public String toString() {
    return "Post{" +
            "title='" + title + '\'' +
            ", body='" + body + '\'' +
            ", userId=" + userId +
            ", id=" + id +
            '}';
   }
}

为什么会出现这个错误?还有什么办法?

感谢任何帮助。

【问题讨论】:

    标签: android interface compiler-errors rx-java retrofit2


    【解决方案1】:

    这个问题的解决方案在于@interface。如果你关注this,那么你会发现它必须被简单地替换为interface

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-24
      • 2016-10-31
      相关资源
      最近更新 更多