File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Display in real time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Display in real time" Watch "Display in real time" New topic

Display in real time

Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
I have a loop that counts down form any x number(say its 100)!

So i can display countdown in real time but in console!
I cant figure it out, how can i put it so it displays on my JLabel! I tried instead System.out , i tried to put JLabel.setText(), but it throws me nullpointExeption!
What am i doing wrong?
Thank you...
pete stein

Joined: Feb 23, 2007
Posts: 1561
What am i doing wrong?

You've got a bug, but where or how, we can't guess without code.

The NPE should tell you which line caused it to be thrown, and you can use that information to your advantage by going to that line, studying it, and trying to figure out which objects are being used on that line and how one of them hasn't been initialized and is throwing the NPE.

You may wish to show us your code, or at least the relevant portions.

Also, you may wish to be careful with the use of the term "real time" as it doesn't quite mean what you think it does.
george boddey

Joined: Feb 16, 2009
Posts: 5
just a quick one, are you using JLabel.setText()? or are you using an instance of jlabel that is part of your gui? for example: myLabel.setText()?
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Repeatedly, not in real time
I called my JLabel vremeJLabel! I am using that name and dont have any sintax mistakes! It just throw me NPE always when program is started!

Sorry about my bad english...
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
first check you've definitely declared the label OK
JLabel vremeJLabel = new JLabel("someText");

if you have, it's likely you have duplicate declarations, something like this

in this example, vremeJLabel will be null when referenced from someMethod()

to fix, make the 2nd declaration just
vremeJLabel = new JLabel("someText");
I agree. Here's the link:
subject: Display in real time
It's not a secret anymore!