473,807 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.NullP ointerException
at javax.swing.tex t.JTextComponen t.getSelectionS tart(JTextCompo nent.java:1503)
at javax.swing.tex t.WrappedPlainV iew.paint(Wrapp edPlainView.jav a:342)
at javax.swing.pla f.basic.BasicTe xtUI$RootView.p aint(BasicTextU I.java:1319)
at javax.swing.pla f.basic.BasicTe xtUI.paintSafel y(BasicTextUI.j ava:636)
at javax.swing.pla f.basic.BasicTe xtUI.paint(Basi cTextUI.java:77 0)
at javax.swing.pla f.basic.BasicTe xtUI.update(Bas icTextUI.java:7 49)
at javax.swing.JCo mponent.paintCo mponent(JCompon ent.java:541)
at javax.swing.JCo mponent.paint(J Component.java: 808)
at javax.swing.JCo mponent.paintCh ildren(JCompone nt.java:647)
at javax.swing.JCo mponent.paint(J Component.java: 817)
at javax.swing.JLa yeredPane.paint (JLayeredPane.j ava:557)

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 3264
> "James Nugent" <je****@york.ac .uk> wrote in message
news:c7******** **@pump1.york.a c.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.NullP ointerException
at javax.swing.tex t.JTextComponen t.getSelectionS tart(JTextCompo nent.java:1503) at javax.swing.tex t.WrappedPlainV iew.paint(Wrapp edPlainView.jav a:342)
at javax.swing.pla f.basic.BasicTe xtUI$RootView.p aint(BasicTextU I.java:1319) at javax.swing.pla f.basic.BasicTe xtUI.paintSafel y(BasicTextUI.j ava:636)
at javax.swing.pla f.basic.BasicTe xtUI.paint(Basi cTextUI.java:77 0)
at javax.swing.pla f.basic.BasicTe xtUI.update(Bas icTextUI.java:7 49)
at javax.swing.JCo mponent.paintCo mponent(JCompon ent.java:541)
at javax.swing.JCo mponent.paint(J Component.java: 808)
at javax.swing.JCo mponent.paintCh ildren(JCompone nt.java:647)
at javax.swing.JCo mponent.paint(J Component.java: 817)
at javax.swing.JLa yeredPane.paint (JLayeredPane.j ava:557)

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.NullP ointerException
at
javax.swing.tex t.JTextComponen t.getSelectionS tart(JTextCompo nent.java:1503)
at javax.swing.tex t.WrappedPlainV iew.paint(Wrapp edPlainView.jav a:342)
at javax.swing.pla f.basic.BasicTe xtUI$RootView.p aint(BasicTextU I.java:1319)
at javax.swing.pla f.basic.BasicTe xtUI.paintSafel y(BasicTextUI.j ava:636)
at javax.swing.pla f.basic.BasicTe xtUI.paint(Basi cTextUI.java:77 0)
at javax.swing.pla f.basic.BasicTe xtUI.update(Bas icTextUI.java:7 49)
at javax.swing.JCo mponent.paintCo mponent(JCompon ent.java:541)
at javax.swing.JCo mponent.paint(J Component.java: 808)
at javax.swing.JCo mponent.paintCh ildren(JCompone nt.java:647)
at javax.swing.JCo mponent.paint(J Component.java: 817)
at javax.swing.JLa yeredPane.paint (JLayeredPane.j ava:557)

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.n et...
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.NullP ointerException
at
javax.swing.tex t.JTextComponen t.getSelectionS tart(JTextCompo nent.java:150
3)


A guess: if you are using label.setText(n ull), 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
5917
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 it would do so. Sample code is : JPanel logoPanel = new JPanel(); logoPanel.setLayout(new BoxLayout(logoPanel, BoxLayout.X_AXIS)); ImageIcon logo = new ImageIcon(_imageFileName);
0
2088
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(" Book Name =") Thanks
3
2210
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 ServerQuitMsg) and in the code i call
0
1262
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 could still be loaded by the consuming application ( concerning the manipulated assembly is a DLL ), The tool uses the unmanaged profiling API to monitor the application being executed ( and actively effect it ), for each assembly being loaded an...
3
6817
by: chramprasad | last post by:
public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { MissionForm missionForm = (MissionForm) form; String strMissionId = InsEncr.getSingleton().decrypt(missionForm.getMissionId().toString()); Long userEntityTypeId = getUserEntityTypeId(request); String strUserEntityTypeId =...
2
25611
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 i clicked... import java.awt.*; import java.awt.event.*; import javax.swing.*;
5
6927
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 id JLabel j2 = new JLabel("Name of DVD = " + dvd); //Displays dvd name JFrame frame = new JFrame( "Matt's DVD's" ); // Sets frame for label frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
3
2367
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 Label with its Label Name or Text.. i tried it by...
1
2044
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 why. Any help would be greatly appreciated int playerCount = 0; private void addPlayerButtonActionPerformed(java.awt.event.ActionEvent evt) { String name = nameTextField.getText();...
0
9599
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10626
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10112
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9193
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.