Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display in real time

 
Ivan Kesic
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a loop that counts down form any x number(say its 100)!
i=100;
while(i>=0){
System.out.println(i);
i--
}

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
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic