I am trying to implement the get color method for the cwac color mixer( https://github.com/commonsguy/cwac-colormixer), but every time this code runs I get a NullPointerException:
int color = 1;
public void openColor(){
ColorMixer mixer = (ColorMixer)findViewById(R.id.mixer);
if (color!=1){
mixer.setColor(color);
}
color = mixer.getColor();
}
The color = mixer.getColor(); is the line that crashes.
I haven’t ever used this Commonsware component before, but from looking at the source code, it appears all you need to do is set up a listener/callback. This mechanism will allow you to get notified of any changes in the color picking.
First, have your class implement the following listener interface:
Then set the listener on the ColorMixer using:
If you do it all inline, it will look somewhat like this: