• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null pointer exception in Multithread Swings program

 
Rahul Kesharwani
Greenhorn
Posts: 15
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rahul Kesharwani
Greenhorn
Posts: 15
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Rahul Kesharwani
Greenhorn
Posts: 15
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic