0

Hey i have a method to get colors and i want to make the color it returns an integer and it does not work! It returns a Color.(java.awt.Color) and i tried: new Integer("0x" + myColor.toString()); and Integer.parseInt("0x" + myColor.toString()); Same result ... The Exeption is a NumberFormatExeption So my question is : Is there any efficient way to make a color code a valid integer?

L.B
  • 19
  • 4
  • Please show your [mcve] code and your full stacktrace exception message. Also, what type of "color code" are you referring to? – Hovercraft Full Of Eels Apr 11 '17 at 17:39
  • ??? just call `getRGB()` ??? -- `myColor.getRGB()`. If this doesn't work there are many more related methods in the [Color API](https://docs.oracle.com/javase/8/docs/api/java/awt/Color.html) that you'll want to look at. – Hovercraft Full Of Eels Apr 11 '17 at 17:43
  • `myColor.toString()` doesn't return a color in hex format (like `ffaaff`). It returns something like `java.awt.Color[r=255,g=170,b=255]` (I'm using java 1.7) and this String causes the `NumberFormatException`. As @HovercraftFullOfEels said, just call `myColor.getRGB()` –  Apr 11 '17 at 17:48
  • In the future, please check the Java API before coming here as that will save you a lot of trouble. Also please check the how to ask a question section of the [help] to see how to ask more complete questions, ones that have enough information to be answerable from the start. – Hovercraft Full Of Eels Apr 11 '17 at 17:50

0 Answers0