Bug 49648

Summary: Hslf Error :Can not replace special characters (€)
Product: POI Reporter: LuK@ <registro72>
Component: HSLFAssignee: POI Developers List <dev>
Status: RESOLVED LATER    
Severity: normal    
Priority: P2    
Version: 3.6-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: PowerPoint for test

Description LuK@ 2010-07-26 08:34:49 UTC
Created attachment 25802 [details]
PowerPoint for test

Hi, 
I urgently need your help. 
First I apologize for my bad English. 
I am a newbie of POI, I'm just venturing into their use. 
My environment is this: 
J2SE 1.5 
Eclipse 
POI 03/06 (20091214) 

I have this problem, I can not replace the text within a text to be replaced when the ppt contains special characters. An example of a special character is €  

Exception in thread "main" java.lang.NullPointerException 
        at org.apache.poi.hslf.model.TextRun.storeText(TextRun.java:350) 
        at org.apache.poi.hslf.model.TextRun.setRawText(TextRun.java:464) 
        at org.apache.poi.hslf.model.TextRun.setText(TextRun.java:498) 
        at ExampleError.main(ExampleError.java:41)


Banging his head on, but unable to solve. 

Below the code that I'm using: 


import org.apache.poi.hslf.HSLFSlideShow; 
import org.apache.poi.hslf.model.Slide; 
import org.apache.poi.hslf.model.TextRun; 
import org.apache.poi.hslf.usermodel.RichTextRun; 
import org.apache.poi.hslf.usermodel.SlideShow; 
import org.apache.poi.poifs.filesystem.POIFSFileSystem; 


public class ExampleError { 

        public static void main(String[] args) { 
                POIFSFileSystem fs; 

                try { 
                        fs = new POIFSFileSystem(new FileInputStream("c://temp//template_test.ppt")); 
                        SlideShow ppt = new SlideShow(new HSLFSlideShow(fs)); 
                        Slide[] slides = ppt.getSlides(); 
                        
                        String replace = "Amount €100"; 
                        
                        int nSlide = slides.length; 

                        for (int i = 0; i < nSlide; i++) { 
                                TextRun[] txtRun = slides[i].getTextRuns(); 
                        
                                for (int j = 0; j < txtRun.length; j++) { 
                                                        
                                        String textGet = txtRun[j].getText(); 
                                        
                                        String txtReplaced = textGet.replace("{txtTot}", replace); 
                                        
                                        System.out.println("Replaced: " + txtReplaced); 
                                        txtRun[j].setText(txtReplaced); 
                                } 
                        } 
                        
                        FileOutputStream out = new FileOutputStream("c://temp//template_final.ppt"); 
                        ppt.write(out); 
                        out.close(); 
                        
                } catch (FileNotFoundException e) { 
                        e.printStackTrace(); 
                } catch (IOException e) { 
                        e.printStackTrace(); 
                } 

        } 

} 

Please find attached a ppt that I use for simple tests. 
Please help I no longer go forward suggestions are welcome, Changes to my code are welcome, you run a small example, would be ideal ... any help is greatly appreciated. 

Best Regards.
Comment 1 Nick Burch 2011-06-24 11:19:29 UTC
I've run your sample program with your file on 3.8 beta 3, and I can change the text to contain unicode characters without error