File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Null pointer exception in Multithread Swings  program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Null pointer exception in Multithread Swings  program" Watch "Null pointer exception in Multithread Swings  program" New topic
Author

Null pointer exception in Multithread Swings program

Rahul Kesharwani
Greenhorn

Joined: Jun 04, 2012
Posts: 15

Hi,

My Application is a multi-thread application, in which a particular set of threads are called repetedly.
This is done under timer event after every 5 seconds.
After say 65 or 70th call to the thread , there is following exception thrown.......repetedly:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2076)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1977)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1773)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
at javax.swing.JComponent.paintComponent(JComponent.java:763)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JViewport.paint(JViewport.java:747)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:278)
at javax.swing.RepaintManager.paint(RepaintManager.java:1220)
at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2076)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1977)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1773)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
at javax.swing.JComponent.paintComponent(JComponent.java:763)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JViewport.paint(JViewport.java:747)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:278)
at javax.swing.RepaintManager.paint(RepaintManager.java:1220)
at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)




I am totally unable to interprete this exception, moreover I cannot make out where and why this exception occurs.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you may not be updating a/the swing component correctly (via the EDT)

there might be some info here

http://docs.oracle.com/javase/tutorial/uiswing/concurrency/
Rahul Kesharwani
Greenhorn

Joined: Jun 04, 2012
Posts: 15

I understood the topic....but I am still not clear with the concept. Moreover how to user this Worker concept in my thread programm,confuses me a lot. Can you help me with an example( actually this is what I am doing in my Gui).


Say, I have to write a programm which regularly checks a status of the process in linux/solaris.
For this, using timer event I execute a process "ps -ef ¦ grep -v grep¦ grep "abc" > file1"
Running this, the output is written in file1
Now using the same thread I have to read the output from that fileand display it on my GUI.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

1. Don't perform any intensive or blocking non-GUI activity on the EDT.
2. Wrap any call to a Swing component method from a background thread in a SwingUtilities#invokeLater.


luck, db
There are no new questions, but there may be new answers.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1836
    
    7

Please don't open duplicate topics. You also asked this very same question in this topic Threads and synchronization, and received a similar anwser. I'm closing that one and you can continu here.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Rahul Kesharwani
Greenhorn

Joined: Jun 04, 2012
Posts: 15

Jelle Klap wrote:Please don't open duplicate topics. You also asked this very same question in this topic Threads and synchronization, and received a similar anwser. I'm closing that one and you can continu here.



Hi,

I opened that thread by mistake. Really sorry
Rahul Kesharwani
Greenhorn

Joined: Jun 04, 2012
Posts: 15

Michael Dunn wrote:you may not be updating a/the swing component correctly (via the EDT)

there might be some info here

http://docs.oracle.com/javase/tutorial/uiswing/concurrency/


Hi Michael,
I have changed the code and replaced it with SwingWorker.



try
{
// statusCheck = new Status();
statusCheck = new Status12();
worker=new SwingWorker(){
public Object doInBackground()throws Exception
{
statusCheck.execute();
return null;
}
protected void done()
{
try
{
data.add(0, "XPA"); //data is a Vector<String>
data.add(1, xpaStatus);
processDetailTable.updateUI(); // Updating processDetailTable (JTable) with XPA status

subData.add(0, "db"); // subData Vector <String> for db
subData.add(1, dbStatus);

subData.add(0, "SV");
subData.add(1, SVStatus);

subProcDetailTable.updateUI(); // Updating subProcDetailTable (JTable) with db status and SV status

}
catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
}

};


int delay = 1; // delay for 0.001 sec.
int period = 10000; // repeat every 5 sec.

Timer timer = new Timer();

timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
panel2.add(processDetPane);
worker.execute();

}
}, delay, period);

Rahul Kesharwani
Greenhorn

Joined: Jun 04, 2012
Posts: 15

Michael Dunn wrote:you may not be updating a/the swing component correctly (via the EDT)

there might be some info here

http://docs.oracle.com/javase/tutorial/uiswing/concurrency/




Michael Dunn wrote:you may not be updating a/the swing component correctly (via the EDT)

there might be some info here

http://docs.oracle.com/javase/tutorial/uiswing/concurrency/


Hi Michael,
I have changed the code and replaced it with SwingWorker, but it`s still not working. The exception is still there.

Following is the core changes I have made:



try
{

statusCheck = new Status12();

worker=new SwingWorker(){
public Object doInBackground()throws Exception
{
statusCheck.execute(); //Here is where Process runs and File is read
return null;
}
protected void done()
{
try
{
data.add(0, "XPA"); //data is a Vector<String>
data.add(1, xpaStatus);
processDetailTable.updateUI(); // Updating processDetailTable (JTable) with XPA status

subData.add(0, "db"); // subData Vector <String> for db
subData.add(1, dbStatus);

subData.add(0, "SV");
subData.add(1, SVStatus);

subProcDetailTable.updateUI(); // Updating subProcDetailTable (JTable) with db status and SV status

}
catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
}

};


int delay = 1; // delay for 0.001 sec.
int period = 10000; // repeat every 5 sec.

Timer timer = new Timer();

timer.scheduleAtFixedRate(new TimerTask() {

public void run() {
panel2.add(processDetPane);
worker.execute();

}
}, delay, period);

Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1096
    
  10

Hi,
In the code, the 'timer' adds a 'processDetPane' to panel1 - this will be done repeatedly which doesn't make sense to me - this will just keep adding JPanel(s) to panel1 - why are you doing that? if you want to update the view, you should update the model of that component...
- and I think you need to call revalidate-repaint when you add/remove components...

Provide us with a SSCCE to help you proceed on this.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Rahul Kesharwani
Greenhorn

Joined: Jun 04, 2012
Posts: 15

Ranganathan Kaliyur Mannar wrote:Hi,
In the code, the 'timer' adds a 'processDetPane' to panel1 - this will be done repeatedly which doesn't make sense to me - this will just keep adding JPanel(s) to panel1 - why are you doing that? if you want to update the view, you should update the model of that component...
- and I think you need to call revalidate-repaint when you add/remove components...

Provide us with a SSCCE to help you proceed on this.



Hi,

That was a misplacement of code. I removed it .
Rahul Kesharwani
Greenhorn

Joined: Jun 04, 2012
Posts: 15

Hi,

Finally My application is up and running successfully. The error is removed. I had to use SwingWorker at multiple levels.
However there is just one issue that concerns me. Due to the use of multiple SwingWorker classes, my application has gone slow.

Does anyone has any idea why my application has slow down .... or .... Is there any way I can speed up my application....
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1096
    
  10

Until you create a SSCCE, it is difficult to help out with the issue.
Also, use code tags when posting code. Click on the link to understand how to do that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null pointer exception in Multithread Swings program