473,396 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Manipulation of JLabel causes nullpointer exception

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
6 3233
> "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
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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: prabhat | last post by:
Hi, I am getting this weird behavior. I have couple of gif and jpg files that I would like to display in JLabel. It displays one jpg image but it does not display other gifs and jpgs. Any idea why...
0
by: Mike | last post by:
Hello, Is there a way of setting text for a JLabel after a certain amount of empty characters. For example, I want to avoid doing this JLabel label = new JLabel(); label.setText(" ...
3
by: nobs | last post by:
Hi guys I think I missunderstud something with delegates & events Hopefully someone can bring some light in this issue: Following problem I have a class which provide some events (like...
0
by: Nadav | last post by:
Hi All, - I am working on a tool that manipulate managed assemblies, some of the functionality provided by the tool require manipulating the metadata sections of the managed assembly in a way it...
3
by: chramprasad | last post by:
public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ...
2
by: reon | last post by:
Hi in this code when i clicked login button...it shows output as login... But when i clicked each time its repeating .. i want to see that only ones ... I want to clear the previous login before...
5
Shinzon
by: Shinzon | last post by:
Ok so I have been working on this for a moment now and wondering how to add multiple jlabels to a jframe. the code looks like this: JLabel jl = new JLabel("DVD ID #= " + dvd); //Displays DVD...
3
nanhiPari
by: nanhiPari | last post by:
hello everyone i need to create DYNAMIC JLABElS(say 5)..yes i know it sounds easy but i also have to give them Events n then want to refer each of them when ever Mouse is Clicked on a Specific...
1
by: tommyny04 | last post by:
I have a method addPlayer that's supposed to add a JLabel to a JPanel and update the JPanel. The JLabel is just a label with a player's name in it. The code I've wrote doesn't work and I'm not sure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.