首页 > 解决方案 > “实际参数列表和形式参数列表的长度不同”

问题描述

我收到此错误:

错误:MainActivity 类中的方法 createOrderSummary 不能应用于给定类型;

必需:整数,布尔值

发现:int

原因:实际参数列表和形式参数列表的长度不同

这是我的代码:

public void submitOrder(View view) {
    CheckBox whippedCreamCheckBox = (CheckBox) findViewById(R.id.whipped_cream_checkbox);
    boolean hasWhippedCream = whippedCreamCheckBox.isChecked();

    int price = calculatePrice();
    String priceMessage = createOrderSummary(int price)
    displayMessage(priceMessage);

}

private String createOrderSummary(int price, boolean addWhippedCream) {
String priceMessage = "Name: Samantha";
priceMessage += "\nAdd Whipped Cream?" + addWhippedCream;
priceMessage += "\nQuantity: " + quantity;
priceMessage += "\nTotal: $" + price;
priceMessage += "\nThank You!";
return priceMessage;

我相信这个问题始于将布尔变量添加到字符串中。我不明白为什么布尔变量感谢您的帮助!

标签: javaxmlstringintboolean

解决方案


传递这些值。我猜你只是在传递int。例子

调用函数

createOrderSummary(20, true);

推荐阅读