-3

I have a string as a parameter in my method and i am trying to print the length of the string in which i have succeded but I want to add a zero in front of the length if it is less than 10.

I am getting the int cannot be referenced error, and not sure what the correct way of doing this is.

public void sendMessage(String message) throws ProtocolException {
    physicalLayer.sendFrame("<" + "E" + "-"
        + message.length().toString().padleft(2, '0')
        + "-" + message + "-" + "00" + ">");
}

Thanks

Zabuzard
  • 25,064
  • 8
  • 58
  • 82
jav_rock
  • 1
  • 5
  • Primitive types don't have methods. So you can't call toString() on an int. Google should help you find out how to transform an int to a String. Note that String doesn't have any padLeft() method. It seems you're calling imaginary methods, instead of reading the javadoc. Don't do that. It won't lead you anywhere. – JB Nizet Nov 18 '17 at 17:31
  • `message.length()` returns a primitive `int` that doesn't have any methods (i.e. there's no `.toString()`. Either use a `Formatter` or do `Integer.valueOf(message.length())` – Jim Garrison Nov 18 '17 at 17:31
  • I get it now, thanks for your help – jav_rock Nov 18 '17 at 18:43

1 Answers1

0

String.format("%02d", message.length())