java - “实际参数列表和形式参数列表的长度不同”
问题描述
我收到此错误:
错误: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;
我相信这个问题始于将布尔变量添加到字符串中。我不明白为什么布尔变量感谢您的帮助!
解决方案
传递这些值。我猜你只是在传递int。例子
调用函数
createOrderSummary(20, true);
推荐阅读
- javascript - 尝试从 material-ui 限制 TextField 并接收 inputRef 错误
- kotlin - 为什么 Kotlin 接口“未打开”?
- java - 使用 Wiremock 验证 Json 主体
- javascript - 单击外部链接时发出警告
- javascript - NodeJS - 直接流式传输到 Azure 数据湖
- java - 如何在 Keycloak 中动态配置 LDAP
- r - 尽管 Rtools 在 PATH 中,但 Sys.which("make") 为空
- excel - 运行时错误 1004:清除下拉列表旁边的单元格
- git - 分支项目
- svg - 当你在 SVG 中倾斜一个矩形时会发生什么?