Timer & Variable Reference
Hi.
I am trying to create a clock on my GUI application but am getting a
NullPointerException error whenever the app runs. This is the code:
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new frmMain().setVisible(true);
}
});
java.util.Timer t = new java.util.Timer();
t.scheduleAtFixedRate(new java.util.TimerTask() {
public void run() {
jLabel1.setText("Test");
}
}, 0, 500);
}
-
This is just a test that was generated using NetBeans and the jLabel has been added through the NetBeans GUI. It is in the variables declaration as
"private static javax.swing.JLabel jLabel1;"
Any ideas what I'm doing wrong? I assume I'm referencing jLabel1
incorrectly somehow...
BTW, before someone asks I'm not using the Swing Timer as I want the timer to consistenly fire at 500 ms and not 500ms + previous overhead.

