You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by yuzhenling <yu...@gmail.com> on 2011/07/06 08:17:33 UTC

poi remove cell comment throw java.lang.NullPointerException

hello, 
 i use poi-3.2-FINAL-20081019.jar, has same problem. 
  when i upload one excel file, write comment on some cell with this excel
and download,then modify cell content where it have comment ,and now the
comment is not be remove .so try again to upload this excel has been
modified. then : java.lang.NullPointerException 
        at
org.apache.poi.hssf.usermodel.HSSFCell.findCellComment(HSSFCell.java:1021) 
        at
org.apache.poi.hssf.usermodel.HSSFCell.getCellComment(HSSFCell.java:952) 
        at
com.**.util.xls.ExcelCellClear.clearComments(ExcelCellClear.java:35) 

java src:for(Iterator<HSSFCell> cellIt = row.cellIterator();
cellIt.hasNext();){ 
                        HSSFCell cell = cellIt.next(); 
                        if(cell != null ){ 
                                if(cell.getCellComment() != null){ 
                                        cell.setCellComment(null); 
                                } 
                                
                        } 
                } 

i debug with program, when 'if(cell != null ){'   cell is not null and it go
'if(cell.getCellComment() != null){' but 
at 'if(cell.getCellComment() != null){' throw java.lang.NullPointerException
,so ...could you give me some method to resolve this problem ,thank you very
much . my english is poor ,sorry please never mind 

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/poi-remove-cell-comment-throw-java-lang-NullPointerException-tp4555849p4555849.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


RE: poi remove cell comment throw java.lang.NullPointerException

Posted by yuzhenling <yu...@gmail.com>.
hi,
  cell.removeCellComment() instead of cell.setComment(null) is also throw
NullPointerException ,so i find poi source code,  in
org.apache.poi.hssf.usermodel.HSSFCell ,at 1021 line,

 for (Iterator it = sheet.getRecords().iterator(); it.hasNext(); ) {
           RecordBase rec = (RecordBase) it.next();
           if (rec instanceof NoteRecord){
               NoteRecord note = (NoteRecord)rec;
               if (note.getRow() == row && note.getColumn() == column){
                   TextObjectRecord txo = (TextObjectRecord)txshapes.get(new
Integer(note.getShapeId()));
                   comment = new HSSFComment(note, txo);
                   comment.setRow(note.getRow());
                   comment.setColumn(note.getColumn());
                   comment.setAuthor(note.getAuthor());
                   comment.setVisible(note.getFlags() ==
NoteRecord.NOTE_VISIBLE);
                   comment.setString(txo.getStr); *//this line txo is null
,so i modify it to'if(txo != null)',the problem is solved but i don't know
why txo is null?maybe it is a bug?*
                   break;
               }

 

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/poi-remove-cell-comment-throw-java-lang-NullPointerException-tp4555849p4559490.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


RE: poi remove cell comment throw java.lang.NullPointerException

Posted by Alex Panayotopoulos <Al...@vianet.co.uk>.
Hi,

Maybe try using cell.removeCellComment() instead?

Thanks,
Alex