亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

“實際和正式的參數列表在長度上有所不同”

“實際和正式的參數列表在長度上有所不同”

飲歌長嘯 2022-08-17 17:32:06
我收到此錯誤:錯誤:方法 createOrderSummary 在類 MainActivity 中不能應用于給定的類型;必需:整型,布爾型已找到: 整型原因:實際參數列表和正式參數列表的長度不同這是我的代碼: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;我認為,問題始于將布爾變量添加到字符串中。我不明白為什么布爾變量感謝您的幫助!
查看完整描述

3 回答

?
回首憶惘然

TA貢獻1847條經驗 獲得超11個贊

您粘貼的方法需要位于類中,因此我將它嵌入到一個類中:


class A{

    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;

    }

}

要調用(調用)它,您需要創建一個類的對象,然后為該對象調用此方法。A


例如:


A a = new A();

a.createOrderSummary(10, true);

new A().createOrderSummary(5, false);

您可以保存此類調用的結果:


string result1 = a.createOrderSummary(10, true);

string result2 = new A().createOrderSummary(5, false);


查看完整回答
反對 回復 2022-08-17
?
心有法竹

TA貢獻1866條經驗 獲得超5個贊

傳遞這些值。你只是通過int我猜。例

調用函數

createOrderSummary(20, true);


查看完整回答
反對 回復 2022-08-17
?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

您對該方法的調用應如下所示:


string SomeString = createOrderSummary(10, true);

您收到的錯誤基本上表明您所做的調用缺少一個參數(可能在您的Main方法中):


//this is wrong. The second argument is missing. 

string SomeString = createOrderSummary(10);

順便說一句。您不能只添加字符串和布爾值。您必須首先轉換布爾值。


boolean addWhippedCream = true;

String str = String.valueOf(addWhippedCream);

System.out.println("The String is: "+ str);


System.out.println("The String is :" + String.valueOf(addWhippedCream));


查看完整回答
反對 回復 2022-08-17
  • 3 回答
  • 0 關注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號