Since you did not mention what class the variable "colorpick" is, I'm going to assume it's ColorPicker (https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ColorPicker.html).
I don't think its hashcode() method is overriden to return the RGB value in hex.
The cause of your error is that black's RGB value is 0. Applying .toHexString() will only give you "0", a single character, hence the .substring() will not work. Other RGB values may also result in a string shorter than 6.
I assume you want the result to be always 6-digit; then you should pad the string with 0 from the start if it's shorter.
Edit
ColorPicker.getValue() returns a Color object, not the RGB value.
So you should use colorpick.getValue().getRGB() instead.
https://docs.oracle.com/javase/7/docs/api/java/awt/Color.html#getRGB()
Edit2
With and without .getRGB():
Color c = Color.CYAN;
String s = Integer.toHexString(c.getRGB() & 0xFFFFFF).toUpperCase();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 6 - s.length(); i++) {
sb.append("0");
}
sb.append(s);
System.out.println(sb.toString());
Color c = Color.CYAN;
int rgbValue = (c.getRed() << 16) + (c.getGreen() << 8) + c.getBlue();
String s = Integer.toHexString(rgbValue & 0xFFFFFF).toUpperCase();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 6 - s.length(); i++) {
sb.append("0");
}
sb.append(s);
System.out.println(sb.toString());
colorpick.getValue(). I think, the problem come from that part.