I have a method setColor, returning float[]. It always returns float array with size=3.
When I use it like this:
float[] color=setColor(0);
content.setColor(Color.getHSBColor(color[0], color[1], color[2]));
there is a NullPointerException.
When I debug my program color[0], color[1], color[2] are defined, but it says that there is a NullPointerException.
How can I fix this?
Here is code of setColor
private float[] setColor (int colorID){
float[]hsbValues=new float[3];
if(colorID == 1){
hsbValues = Color.RGBtoHSB(0,255,255,hsbValues);
}
else if(colorID == 2){
hsbValues = Color.RGBtoHSB(255,0,255,hsbValues);
}
else if(colorID == 3){
hsbValues = Color.RGBtoHSB(0,255,0,hsbValues);
}
else if(colorID == 4){
hsbValues = Color.RGBtoHSB(255,255,0,hsbValues);
}
else if(colorID == 5){
hsbValues = Color.RGBtoHSB(255,0,0,hsbValues);
}
else if(colorID == 6){
hsbValues = Color.RGBtoHSB(255,255,255,hsbValues);
}
else{
hsbValues = Color.RGBtoHSB(0, 0, 0,hsbValues);
}
return hsbValues;
}
Here is constructor of class.
DrawOutput (MinDistances requiredMinDistances, MainMatrix matrix){
super();
getRequiredMedoidsArray(requiredMinDistances);
paint(getGraphics(), requiredMinDistances, matrix);
}
getGraphics is null, Any suggestions?