By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,541 Members | 1,106 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,541 IT Pros & Developers. It's quick & easy.

Manipulation of JLabel causes nullpointer exception

P: n/a
Hi everyone,

My app need to manipulate JLabels that have been added to the pane. All I need to do is simple stuff like make them disappear or change their background color.

Unfortunately (and only from time to time) I get null pointer exceptions:
java.lang.NullPointerException
at javax.swing.text.JTextComponent.getSelectionStart( JTextComponent.java:1503)
at javax.swing.text.WrappedPlainView.paint(WrappedPla inView.java:342)
at javax.swing.plaf.basic.BasicTextUI$RootView.paint( BasicTextUI.java:1319)
at javax.swing.plaf.basic.BasicTextUI.paintSafely(Bas icTextUI.java:636)
at javax.swing.plaf.basic.BasicTextUI.paint(BasicText UI.java:770)
at javax.swing.plaf.basic.BasicTextUI.update(BasicTex tUI.java:749)
at javax.swing.JComponent.paintComponent(JComponent.j ava:541)
at javax.swing.JComponent.paint(JComponent.java:808)
at javax.swing.JComponent.paintChildren(JComponent.ja va:647)
at javax.swing.JComponent.paint(JComponent.java:817)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:5 57)

As you can see, the stack trace doesn't point to any lines in my code but to the swing libraries instead.

Please help!

Thanks,
James
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
> "James Nugent" <je****@york.ac.uk> wrote in message
news:c7**********@pump1.york.ac.uk...
Hi everyone,

My app need to manipulate JLabels that have been added to the pane. All I need to do is simple stuff like make them disappear or change their background color. Unfortunately (and only from time to time) I get null pointer exceptions:
java.lang.NullPointerException
at javax.swing.text.JTextComponent.getSelectionStart( JTextComponent.java:1503) at javax.swing.text.WrappedPlainView.paint(WrappedPla inView.java:342)
at javax.swing.plaf.basic.BasicTextUI$RootView.paint( BasicTextUI.java:1319) at javax.swing.plaf.basic.BasicTextUI.paintSafely(Bas icTextUI.java:636)
at javax.swing.plaf.basic.BasicTextUI.paint(BasicText UI.java:770)
at javax.swing.plaf.basic.BasicTextUI.update(BasicTex tUI.java:749)
at javax.swing.JComponent.paintComponent(JComponent.j ava:541)
at javax.swing.JComponent.paint(JComponent.java:808)
at javax.swing.JComponent.paintChildren(JComponent.ja va:647)
at javax.swing.JComponent.paint(JComponent.java:817)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:5 57)

As you can see, the stack trace doesn't point to any lines in my code but to the swing libraries instead.

Please help!

Thanks,
James


First, please don't post in HTML. Second, don't post questions to
comp.lang.java. It's not a "real" newsgroup. Finally, nobody can help you if
you don't show us your code.
Jul 17 '05 #2

P: n/a
it's been my experience that there are two primary causes of this
problem... the first is that your JRE setup might be a bit confused. if
you have more than one, it's possible some x-referencing is going on.

another area however, it to examine just how the JLabel class is
intended to be used. are you doing something with it for which your
stretching the limits of it's specification ? or is there an example
program around that can show you what you are trying to do with it
outside of your application.

cheers

- perry
James Nugent wrote:
Hi everyone,

My app need to manipulate JLabels that have been added to the pane. All
I need to do is simple stuff like make them disappear or change their
background color.

Unfortunately (and only from time to time) I get null pointer exceptions:
java.lang.NullPointerException
at
javax.swing.text.JTextComponent.getSelectionStart( JTextComponent.java:1503)
at javax.swing.text.WrappedPlainView.paint(WrappedPla inView.java:342)
at javax.swing.plaf.basic.BasicTextUI$RootView.paint( BasicTextUI.java:1319)
at javax.swing.plaf.basic.BasicTextUI.paintSafely(Bas icTextUI.java:636)
at javax.swing.plaf.basic.BasicTextUI.paint(BasicText UI.java:770)
at javax.swing.plaf.basic.BasicTextUI.update(BasicTex tUI.java:749)
at javax.swing.JComponent.paintComponent(JComponent.j ava:541)
at javax.swing.JComponent.paint(JComponent.java:808)
at javax.swing.JComponent.paintChildren(JComponent.ja va:647)
at javax.swing.JComponent.paint(JComponent.java:817)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:5 57)

As you can see, the stack trace doesn't point to any lines in my code
but to the swing libraries instead.

Please help!

Thanks,
James


Jul 17 '05 #3

P: n/a
On Thu, 06 May 2004 13:05:33 -0400, perry wrote:

(re NPE)
it's been my experience that there are two primary causes of this
problem... the first is that your JRE setup might be a bit confused. if
you have more than one, it's possible some x-referencing is going on.


This is the first I have heard of
this particular problem. Do you
have further details?

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 17 '05 #4

P: n/a
Liz

"Andrew Thompson" <Se********@www.invalid> wrote in message
news:f1*****************************@40tude.net...
On Thu, 06 May 2004 13:05:33 -0400, perry wrote:

(re NPE)
it's been my experience that there are two primary causes of this
problem... the first is that your JRE setup might be a bit confused. if
you have more than one, it's possible some x-referencing is going on.


This is the first I have heard of
this particular problem. Do you
have further details?


When you make the label disappear do you use "dispose()"?
Jul 17 '05 #5

P: n/a
the JLabel problem he is speaking of, which seems to create a NPE deep
inside JRE libraries was a surprise for me when i came across it the
first time. i managed to trace and backtrace the execution and
double-checked my parameters and everything seemed fine.

however, it's been my experience that when faced with a situation that
just doesn't make sense, it's time to sit back and do some house
cleaning. in my case, i discovered i had not just two but several
versions and implementations of the JRE on my system. not only was this
unnecessary and was taking up space, but after i went thru the trouble
of removing all the JREs and then putting the one i needed back, my code
work perfectly.

such was my experience. and from the sounds of things this is what this
person is facing as well.

- perry
Andrew Thompson wrote:
On Thu, 06 May 2004 13:05:33 -0400, perry wrote:

(re NPE)
it's been my experience that there are two primary causes of this
problem... the first is that your JRE setup might be a bit confused. if
you have more than one, it's possible some x-referencing is going on.

This is the first I have heard of
this particular problem. Do you
have further details?


Jul 17 '05 #6

P: n/a
"James Nugent" <je****@york.ac.uk> wrote in message news:<c7**********@pump1.york.ac.uk>...
Hi everyone,

My app need to manipulate JLabels that have been added to the pane. All
I need to do is simple stuff like make them disappear or change their
background color.

Unfortunately (and only from time to time) I get null pointer
exceptions:
java.lang.NullPointerException
at
javax.swing.text.JTextComponent.getSelectionStart( JTextComponent.java:150
3)


A guess: if you are using label.setText(null), try label.setText("") instead.
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.