When I attempt to compile below code I receive the error “Constructor call must be the first statement in a constructor”. Im receiving the error at line this(text, style, font, colour, backgroundBitmap);
Im not within the constructor, im just trying to call it from an initialise method.
public class TimerLabelFieldSingleton extends TimerLabelField{
private TimerLabelFieldSingleton ref;
private TimerLabelFieldSingleton(Object text, long style, Font font,
int colour, Bitmap backgroundBitmap) {
super(text, style, font, colour, backgroundBitmap);
}
private void initialise(Object text, long style, Font font,int colour, Bitmap backgroundBitmap){
this(text, style, font, colour, backgroundBitmap);
}
public TimerLabelFieldSingleton getSingletonObject(Object text, long style, Font font,int colour, Bitmap backgroundBitmap){
if(ref == null){
ref = new TimerLabelFieldSingleton(text, style, font,colour, backgroundBitmap);
}
return ref;
}
}
It is not allowed to call the constructor (or
superconstructor) from anywhere else but in the constructor it self. In other words, you cannot callthis()from another method than the constructor.