Greetings,

Context:

I am trying to create a ppt where each page has a graph and may or may not
have a table with text.

The text in the table cells needs to be multicolored - some text red or
green - other text black.

When trying to create rich text runs so that I can set the color of the
various substrings I am getting an NPE.

Here is some code that reproduces the problem:

package test;

import java.awt.Color;

import org.apache.poi.hslf.model.Table;
import org.apache.poi.hslf.model.TableCell;
import org.apache.poi.hslf.model.TextRun;
import org.apache.poi.hslf.usermodel.RichTextRun;

public class PPTPlay
{

    public static void main(String[] args)
    {
        Table t= new Table(1,1);
        TableCell tc = t.getCell(0, 0);
        TextRun tr = tc.getTextRun();
        tr.setRawText("this is test text");
        RichTextRun rtr = new RichTextRun(tr,0,5);
        rtr.setFontColor(Color.green);
    }

}

which generates:

Exception in thread "main" java.lang.NullPointerException
    at
org.apache.poi.hslf.usermodel.RichTextRun.fetchOrAddTextProp(RichTextRun.java:262)
    at
org.apache.poi.hslf.usermodel.RichTextRun.setCharTextPropVal(RichTextRun.java:343)
    at
org.apache.poi.hslf.usermodel.RichTextRun.setFontColor(RichTextRun.java:532)
    at
org.apache.poi.hslf.usermodel.RichTextRun.setFontColor(RichTextRun.java:541)
    at test.PPTPlay.main(PPTPlay.java:23)


I am using 3.6 poi and scratchpad.

Should I be creating RichTextRun's differently?

Thanks

Matthias

Reply via email to