Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/05/2012, 03:16
Avatar de caruizj
caruizj
 
Fecha de Ingreso: marzo-2012
Ubicación: Málaga
Mensajes: 161
Antigüedad: 12 años, 10 meses
Puntos: 14
Duda con null y cadena vacía

Buenos días,

Estoy exportando un JTable a un excel y en un campo puede haber valores null o cadena vacía.

La cadena vacía no me importa pero el valor null luego cuando abro la hoja de excel se ve null y queda muy feo.

Lo estoy intentando controlar desde código pero no consigo hacerlo.

Lo que hago es lo siguiente:


// RECORRER LA TABLA

for(int i=0;i< tabla.getColumnCount();i++){
for(int j=0;j<tabla.getRowCount();j++){

Object objeto=tabla.getValueAt(j,i);


// VER SI EL CAMPO ES NULO O VACIO
if (objeto.toString().equals("")) System.out.println("vacio");
else if (objeto.toString().equals(null)) System.out.println("nulo");

// Insertar campo en excel
s.addCell(new Label(i, j+1, String.valueOf(objeto)));


}


Y el error que me sale es el siguiente:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ExportarExcel.ExportarExcel.export(ExportarExcel.j ava:76)
at ExportarExcel.ExportarExcel.<init>(ExportarExcel.j ava:35)
at VentanaPrincipal.VentanaPrincipal$4.actionPerforme d(VentanaPrincipal.java:599)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown 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.mouseRe leased(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(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn 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.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


Como puedo compararlo para que no me de error?

Un saludo y gracias.
__________________
Aprendiendo un poco de Java :D