0

TextArea オブジェクトを使用しているときに、ControlP5 でこの問題が発生しました。

setText(fooString)fooString の行に ' ' が含まれている場合に' ' を呼び出すと、Java はヌル ポインター例外をスローします。

例えば:

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 スロー: " StringIndexOutOfBoundsException" および " NullPointerException"

私の回避策( s = "[スペースの束]" というケースを無視して):

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

これを修正するより良い方法はありますか、それとも上記のコードの (私の側の) バグですか?

4

0 に答える 0