我正在制作食谱应用程序,但遇到此错误:类HomeItem中的构造函数HomeItem无法应用于给定类型;
        recipe.add(new HomeItem(“ viay”,R.drawable.vietnamese));

这是我的代码:


  公共类HomeFragment扩展Fragment {
      查看v;
      私人RecyclerView myrecyclerview;
      私人清单食谱;
      公共HomeFragment(){
      }

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

  
  v = inflater.inflate(R.layout.fragment_home,container,false);
  
  返回v;
      }

public interface OnFragmentInteractionListener {
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    recipe = new ArrayList<>();
    recipe.add(new HomeItem("viay",R.drawable.vietnamese));
}



}

这是HomeItem.java:


  公共类HomeItem {

private String RecipeName;
private int RecipeImage;

public HomeItem() {

}

public String getRecipeName() {
    return RecipeName;
}

public int getRecipeImage() {
    return RecipeImage;
}

public void setRecipeName(String recipeName) {
    RecipeName = recipeName;
}

public void setRecipeImage(int recipeImage) {
    RecipeImage = recipeImage;
}

  
  }


我在HomeItem中声明了什么错误?谢谢

最佳答案

您不能将参数传递给不带参数的构造函数。

尝试这个

public HomeItem(String recipieName, int recipieImage) {
    this.recipieName=recipieName;
    this.recipieImage=recipieImage;
}


ps。使用骆驼的情况下变量和领域

08-04 17:02