Skip to main content

Null Pointer in ViewerColumn of TableViewer on call of setInput

If you are getting the the NPE whle creating the TableViewer and your stack trace looks somewhat like this:


java.lang.NullPointerException
at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:145)
at org.eclipse.jface.viewers.AbstractTableViewer.doUpdateItem(AbstractTableViewer.java:399)
at org.eclipse.jface.viewers.StructuredViewer$UpdateItemSafeRunnable.run(StructuredViewer.java:481)
at org.eclipse.jface.util.SafeRunnable$1.run(SafeRunnable.java:128)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.StructuredViewer.updateItem(StructuredViewer.java:2111)
at org.eclipse.jface.viewers.AbstractTableViewer.createItem(AbstractTableViewer.java:277)
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefreshAll(AbstractTableViewer.java:757)
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(AbstractTableViewer.java:649)
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(AbstractTableViewer.java:636)
at org.eclipse.jface.viewers.AbstractTableViewer$2.run(AbstractTableViewer.java:592)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1392)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1353)
at org.eclipse.jface.viewers.AbstractTableViewer.inputChanged(AbstractTableViewer.java:590)
at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:274)
at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1634)

Than you encountered a very silly problem, and generally silly problems are hard to debug which is exactly the case with above exception. There are two ways of setting the label provider on your TableViewer component as follows:

Scenario 1:
1. Creating JFace TableViewer and calling setLabelProvider on it
2. Creating your swt TableColumns

Scenario 2:
1. Creating JFace TableViewer
2. Creating JFace TableViewerColumn and set ColumnLabelProvider on it


My colleague faced the problem in Scenario 1 and asked me to help him in it. As he told me that he was debugging from some time now and the problem gets resolved if Scenario 1: is changed to:

Scenario 1(modified):

1. Creating JFace TableViewer
2. Creating your swt TableColumn
3. Call setLabelProvider on TableViewer

I hope this will solve your problem.

Enjoy coding :-)

Comments

Post a Comment

Popular posts from this blog

Master Detail

Master-Detail Eclipse Forms I just finished working on the editor which uses the Master-Detail pattern of the eclipse forms. During which I faced several problems like: In my master block, when the size of table-viewer increased, the master block shows the scrollbar instead of table-viewer. Also, it made the length of the detail and master parts equal which made my editor unusable Detail part having scroll problems like the one mentioned above Setting the details part data-dynamically was yet another area where I faced a lot of problem In this blog, I will be giving a brief introduction about the master-detail pattern and will be addressing the problems mentioned above. The article by Dejan Glozic is really helpful and explains the basics of the eclipse forms. I’ll be explaining the stuff using FUSE Integration Designer(FID) which is an open source and available for download . And the screen-shots will be from the Messaging module of the FID using the example of JMS Messages . In

Interview at Progress Software

I have given a lot of interviews before however, this one was special. Let me start from the beginning. I got a call from Progress Software and was scheduled for the first telephonic discussion. Next day, I got a call from HR and she asked me questions on Java and a few basic puzzles.  After clearing the previous round, I got scheduled for the second telephonic interview. This interview covered Java, design-related problems and algorithms. After a week, I got a call from the HR for the onsite interviews in Hyderabad. This is the first time I googled about Progress Software. I said yes for the onsite interviews. Journey to onsite started not as planned after my flight got delayed. Because of fog-related delay in Delhi, I reached the PSI (Progress Software India) office couple of hours late.  HR introduced me to the first interviewer. The interviewer explained the first round. It was a coding round (I am not a big fan of coding rounds), the problem was well expl

java.net.SocketException: Connection reset

I am able to fix the problem via setting the following params on the HTTPClient class... client.getParams().setParameter("http.socket.timeout", new Integer(0)); client.getParams().setParameter("http.connection.stalecheck", new Boolean(true)); java.net.SocketException: Connection reset at java.net.SocketInputStream.read(Unknown Source) at java.io.BufferedInputStream.fill(Unknown Source) at java.io.BufferedInputStream.read(Unknown Source) at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:77) at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:105) at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1115) at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1832) at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590) at org.apache.commons.httpclient.HttpMethodBase.execute(