0

I've encountered this issue with ControlP5 when using the TextArea object:

When calling 'setText(fooString)' if fooString contains a ' ' in a line by itself, Java will throw a null pointer exception.

For example:

void setup()
{
  size(300,300);
  cp5 = new ControlP5(this);
  textArea = cp5.addTextarea("txt")
                  .setPosition(0,0)
                  .setSize(30,30)
                  .setFont(createFont("arial",12))
                  .setLineHeight(14)
                  .setColor(color(0))
                  .setColorBackground(color(0))
                  .setColorForeground(color(255,100));
                  ;
  String s = "Hello\n       \nworld";
  textArea.setText(s);
}

Java throws: "StringIndexOutOfBoundsException" and "NullPointerException"

My workaround (ignoring the case that s = "[a bunch of spaces]"):

s = s.replaceAll("\r", "\n");    // Use just one type of new line
s = s.replaceAll("\n +", "\n");  // Case 1
s = s.replaceAll(" +\n", "\n");  // Case 2

Is there a better way to fixing this or is a bug (on my part) with the above code?

2
  • What version of ControlP5 are you using ? I've just tested this: import controlP5.*; ControlP5 cp5; Textarea textArea; void setup() { size(300,300); cp5 = new ControlP5(this); textArea = cp5.addTextarea("txt","txt",0,0,30,60); String s = "Hello\n \nworld"; textArea.setText(s); } with 0.5.4 and it works fine Feb 7, 2013 at 11:53
  • Hmm, according to the library.properties file: 2.0.4, which appears to be the latest version.
    – funseiki
    Feb 7, 2013 at 16:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy