Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Export Excel raises NPE
Export Excel raises NPE [message #1720222] Fri, 15 January 2016 11:09 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
Hello,

Today i tried to export my Table as Excel (Ctrl+E) but this ends in a NPE

java.lang.NullPointerException
	at org.eclipse.nebula.widgets.nattable.export.excel.DefaultExportFormatter.formatForExport(DefaultExportFormatter.java:29)
	at org.eclipse.nebula.widgets.nattable.export.NatExporter.exportLayer(NatExporter.java:217)
	at org.eclipse.nebula.widgets.nattable.export.NatExporter$1.run(NatExporter.java:69)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4155)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3772)


Do i have to configure something to use this Feature?
i thought this should work OOTB like printing.

NOTE: printing the table works without troubles (Ctrl+P)

thanks in advance
Ludwig
Re: Export Excel raises NPE [message #1720223 is a reply to message #1720222] Fri, 15 January 2016 11:33 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Looks like you have no IDisplayConverter configured. Which makes me wonder, because the DefaultNatTableStyleConfiguration adds at least the DefaultDisplayConverter as most common one.

Feel free to file a ticket that in such a case the DefaultDisplayConverter is used as fallback instead of raising a NPE.
Re: Export Excel raises NPE [message #1720225 is a reply to message #1720223] Fri, 15 January 2016 11:51 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i now checked if i have such a Configuration in use, and i do have...
DefaultNatTableStyleConfiguration natTableConfiguration = new DefaultNatTableStyleConfiguration();
natTableConfiguration.bgColor = GUIHelper.COLOR_WHITE;
natTableConfiguration.fgColor = GUIHelper.COLOR_BLACK;
natTableConfiguration.hAlign = HorizontalAlignmentEnum.LEFT;
natTableConfiguration.vAlign = VerticalAlignmentEnum.MIDDLE;
...
natTable.addConfiguration(natTableConfiguration);
natTable.addConfiguration(rowStyleConfiguration);
natTable.addConfiguration(selectionStyle);


NOTE: i am using NatTable 1.3

created ticket #(485921)
Re: Export Excel raises NPE [message #1720227 is a reply to message #1720225] Fri, 15 January 2016 12:21 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
In that case I wonder why there is a NPE. It would be interesting to see for which cell no display converter can be found. Even with the fix to use the DefaultDisplayConverter you might face other issues if you have registered different converters and they are not reflected on exporting.
Re: Export Excel raises NPE [message #1720376 is a reply to message #1720227] Mon, 18 January 2016 09:40 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i have no clue if this might cause the problem but:
i just had a look into org.eclipse.nebula.widgets.nattable.data.convert package and noticed several DisplayConverters for several DataTypes.
i do use Calendar in my Application, but there is no DisplayConverter for this Class (though i do not think this will be a problem as the DefaultConverter would convert the Calendar toString then... right?)

i do not register any converters yet (i only convert the Objects to String - i have no cell editors in the table)

how can i find out which cell does not have a DisplayConverter?
Re: Export Excel raises NPE [message #1720380 is a reply to message #1720376] Mon, 18 January 2016 09:58 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Answering your question, yes the DefaultDisplayConverter simply returns Object#toString(). And yes there is no default IDisplayConverter for Calendar in NatTable. Currently there is only one for java.util.Date.

The IDisplayConverter is also used for normal rendering, not only for editing.

I would have started by setting a conditionalo breakpoint to the DefaultExportFormatter when displayConverter == null. And then check which ILayerCell you have (which labels and so on).
Re: Export Excel raises NPE [message #1720385 is a reply to message #1720380] Mon, 18 January 2016 10:27 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i now implemented a CustomExportFormatter and required Classes.
it turned out that the problem is located in the Corner.
i do print the number of rows there.

so by adding
if (displayConverter == null) {
	return new DefaultDisplayConverter().canonicalToDisplayValue(cell, configRegistry, dataValue);
	// return dataValue brings the same result in my case
	}
}


the export is working!

Re: Export Excel raises NPE [message #1720391 is a reply to message #1720385] Mon, 18 January 2016 10:48 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Interesting ... as the DefaultNatTableStyleConfiguration adds the DefaultDisplayConverter non label dependent, even the corner should have the DefaultDisplayConverter. So it might be that you override that by setting null as displayconverter for the corner?

I already fixed the NPE issue on master similarly.
Re: Export Excel raises NPE [message #1720394 is a reply to message #1720391] Mon, 18 January 2016 11:07 Go to previous message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i doubt so. i searched my code for 'corner' and got only a few results
DefaultNatTableThemeConfiguration:
styleCornerLikeColumnHeader = false
corherHAlign
cornerFont
CornerCellPainter


and the data provided by the cornerLayer:
ILayer cornerLayer = new CornerLayer(
	new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider) {
		@Override
		public Object getDataValue(int columnIndex, int rowIndex) {
		return getDataSource().getList().size(); // simply return the size of the list in the table
	}
	}), rowHeaderLayer, columnHeaderLayerStack);


none of this should remove a DisplayConverter.

further and i do not have a single class that uses CellConfigAttributes.DISPLAY_CONVERTER (beside the new CustomExportFormatter, created during this Thread)
Previous Topic:set Background color to row based on condition
Next Topic:Different SpanningDataBodyDataProvider for nattable
Goto Forum:
  


Current Time: Fri Apr 26 11:20:07 GMT 2024

Powered by FUDForum. Page generated in 0.03833 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top