尝试在以下代码中实现setHeadline()
时遇到“实际和形式参数列表的长度不同”错误。
private void setupAdaptater() {
mPostAdapter = new FirebaseRecyclerAdapter < Post, PostViewHolder > (
Post.class,
R.layout.item_layout_post,
PostViewHolder.class,
mPostRef
) {
@Override
protected void populateViewHolder(PostViewHolder viewHolder, final Post model, int position) {
StorageReference storageReference = FirebaseStorage.getInstance().getReferenceFromUrl(model.getImageUrl());
Glide.with(MainActivity.this)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(viewHolder.postIV);
viewHolder.setHeadline(model.setHeadline()); //Headline
viewHolder.setNumLikes(model.getNumLikes());
viewHolder.postLikeIV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateNumLikes(model.getUID());
}
});
}
};
}
//...
public void setHeadline(String headline){ //Headline
postHeadline.setText(String.valueOf(headline)); //This string gives the value of headline_event
}
我定义这样的字符串:
public class Post {
private String headline; //Set headline as String;
public Post() {
}
public Post(String headline) {
this.headline = headline; //This is the headline that was added
}
public void setHeadline(String headline) { //Set the headline
this.headline = headline; //set the headline as string
}
//..
我不会弄到长度不匹配的地方。谁能帮我这个?
最佳答案
在您的Post
类中,我看到以下代码:
您似乎在这里打了一个错字:方法是 g etHeadline,但它看起来像个“设置者”,因此应命名为 s etHeadline。
我希望看到两个看起来像这样的方法:
public String getHeadline() {
return headline;
}
public void setHeadling(String headline) {
this.headline = headline;
}