Home > Enterprise >  I cannot concatenate a variable string variable this line of code gives me a error "None of
I cannot concatenate a variable string variable this line of code gives me a error "None of

Time:05-13

I'm a newcomer in this, and I'm learning kotlin in android studio, and I'm stacked in this error, "None of the following functions can be called with the arguments supplied" when I want to concatenate a variable string variable the error appears, and when delete the first variable and the plus signal the error disappears, Could anyone help me whit this? this is the part of the code

 /**
     * This method is called when the order button is clicked.
     */
    fun submitOrder(view: View?) {
        var price = quantity * 5
        var  priceMessage = price   "dollars for  "   quantity   " of coffee. Pay up"
        displayMessage(priceMessage)
    }

CodePudding user response:

price "dollars for " won't work because you can't add a string to a number. If you want to concatenate them all, you can do like this using string templates:

val priceMessage = "$price dollars for $quantity of coffee. Pay up"
  • Related