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.

[1006 byte] By [USFJosepha] at [2007-11-27 8:43:32]
# 1
NPE where? And please read this: http://forum.java.sun.com/help.jspa?sec=formattingIf it's related to the JLabel - how about mking sure you actually initialize that reference?
CeciNEstPasUnProgrammeura at 2007-7-12 20:43:16 > top of Java-index,Java Essentials,Java Programming...
# 2

Sorry I'm a bit new to Java -- what is NPE? Also, my apologies for not posting in the proper format; I'll remember that for the future as there doesn't seem to be a way to edit the post now.

Regarding initializing the reference to the jLabel -- doesn't the variable declaration, "private static javax.swing.JLabel jLabel1;" do that?

Thanks.

USFJosepha at 2007-7-12 20:43:16 > top of Java-index,Java Essentials,Java Programming...
# 3

Ahh -- NPE = NullPointerException.

The error I get is:

Exception in thread "Timer-0" java.lang.NullPointerException

at prg.frmMain$2.run(frmMain.java:216)

at java.util.TimerThread.mainLoop(Timer.java:512)

at java.util.TimerThread.run(Timer.java:462)

USFJosepha at 2007-7-12 20:43:16 > top of Java-index,Java Essentials,Java Programming...
# 4
Figured it out :)For those who may stumble upon this the following webpage helped alot: http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
USFJosepha at 2007-7-12 20:43:16 > top of Java-index,Java Essentials,Java Programming...