Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Getting Null Pointer Exception when getting the value after cell ediiting in Jtable

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can any one please help me in solving the error of Null Pointer Exception when getting the value of a cell after editing in Jtable


I am using the code as foolows





Can any one help me in "where I had commited wrong in my code",

and please suggest me to get rid of this error,


Thank you very much,
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would help if you posted a short piece of runnable code that demonstrated the problem, as well as posting the entire text of the Exception, pointing out any line numbers referenced in the stack trace.
 
Rancher
Posts: 3205
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You where given the answer two days ago in your other posting.
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Rob Camick Sir,

I had included the stopcellEditing(), also

you can see that in line 77 in my code

But still I am getting the Null Pointer Exception

So for that I am asking where I had been mistaken because I am new to this topic,


Thnak you very much,
 
Rob Camick
Rancher
Posts: 3205
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) I suggested you use the default editor, you are still using your custom editor

2) I suggested you use the getValueAt(...) method. You are still using your old code.

3) I gave you a link that showed a couple of different ways to stop editing of a cell. One solution was 1 line of code, the other was 2 lines of code. Instead you come up with nested for loops for some reason which looks nothing like the code I suggested.

You have not followed any of my suggestions so I'm not about to spend time debugging your code.
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Rob Camick Sir,

I don't have any idea about this cell editing,

I don't Know about Default cell editing and custum cell editing but I read now some examples and I found a piece of code like this,




Can you please suggest a link or any documentation to know the difference between custom cell editor and default cell editor,


If you help me I willl be very much thankful to you,
 
Sheriff
Posts: 21999
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still see nothing Kevin or Rob C asked for. How about that stack trace, for instance?
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime Sir,

The Stack trace is as follows



Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at client.cpm.dailyT8.alarm.CBRCPMDailyT8Update.updateButton_actionPerformed(CBRCPMDailyT8Update.java:121)
at client.cpm.dailyT8.alarm.CBRCPMDailyT8Update.access$0(CBRCPMDailyT8Update.java:102)
at client.cpm.dailyT8.alarm.CBRCPMDailyT8Update$1.actionPerformed(CBRCPMDailyT8Update.java:95)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)




please tell me sir how to use DefaultCell Editor for cell editing and how to get the value after editing,

It is very important for me or please suggest me any Links so that I can go on,

Thank you very much
 
Rob Spoor
Sheriff
Posts: 21999
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Kushi Gadiparthi wrote:

at client.cpm.dailyT8.alarm.CBRCPMDailyT8Update.updateButton_actionPerformed(CBRCPMDailyT8Update.java:121)


So there you have the exact line where the error occurs: 121. If we analyze the method in which it occurs (updateButton_actionPerformed), there are a few possibilities (mentioned in comments):
Why I think that this.getTable().getCellEditor() returns null? Because that's what the API says:

Returns:
the TableCellEditor that does the editing, or null if the table is not currently editing.


You loop through all cells. If the cell is editable (not being edited, being editable; big difference!) you get the single available cell editor and tell it to stop editing. Unless this fails that means that after the first call the table is not currently editing any more. Any subsequent call to this.getTable().getCellEditor() will return null. And since you are looping through all cells, there is bound to be another editable cell and you call the method again.

Replace your entire loop with a simple if statement:
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Rob Prime Sir,

Thank you very much for your help

I had replaced my hole loop like this



But now I am not getting the error and I am not getting the edited value also,

Help me in this,

Thank you very much
 
Rob Spoor
Sheriff
Posts: 21999
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because editor is a new table cell editor that's not attached to the table in any way. You'll need to use the old editor:
This is just basic code, without proper handling of a null editor or a null editor value.
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Rob Prime Sir,

I did not understand this logic,

But where we giving reference to MyTableCellEditor class

Can you please explian me,


Thank you very much,
 
Rob Spoor
Sheriff
Posts: 21999
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to set it for the table, or table column. Check out the APIs of JTable and TableColumn. Inside your action listener you don't need a reference to it anymore.
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Sir,


thank you very much for your help,

Today I had came to know some new things with your help,


My Editing had worked perfectly,


Thanks a lot,
 
Rob Spoor
Sheriff
Posts: 21999
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Rob Camick
Rancher
Posts: 3205
29
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code may work, but as far as I'm concerned the code is WRONG. There is no need to reference the actual cell editor to get the data. When the cell is finished editing the editor will automatically save the data to the TableModel, which is why I suggested long ago to use the getValueAt(...) method.

There is still no need to write a custom editor either. The JTable will use the default edtior by default.

All you have to do is read the JTable API and you will find a link to the Swing tutorial on "How to Use Tables" Which has example code.
 
    Bookmark Topic Watch Topic
  • New Topic