I have the following code implemented in Java.
public class FadeLabel extends javax.swing.JLabel {
private Timer onTimer;
public FadeLabel() {
init();
}
private void init(){
setHorizontalAlignment(CENTER);
setVerticalAlignment(CENTER);
onTimer = new Timer(100, (ActionEvent e) -> {
// animation code
});
}
@Override
public void setText(String text) {
onTimer.start();
super.setText(text);
}
}
When I create an object of this class, it gives a NullPointerException
in the setText()
method, the line onTimer.start()
.
I want to know why is this exception happening..?
ps: I know what is a NullPointerException
is. I want to know how is it generated here..
This is how I instantiate.
notificationLabel = new FadeLabel();