Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

string.getlength does not work?

$
0
0
hi guys.

im getting an exception everytime i try to get the length of a string and I dont know how to fix this.
does anybody have an idea?

Heres my code:

import processing.serial.*;

Serial myPort;  // Create object from Serial class
String SerialBuffer;      // Data received from the serial port

void setup() 
{
  size(500,128);
  String portName = Serial.list()[5];
  myPort = new Serial(this, portName, 115200);
}

void draw()
{
  background(0);
  stroke(255);
  if ( myPort.available() > 0) {  // If data is available,
    SerialBuffer = myPort.readString();         // read it and store it in val
  }
  
  if (SerialBuffer==""){
  }
  else{
    int BufLen = BufLen=SerialBuffer.length(); //Here is where I get a NullPointerException
    for (int i=0; i<129; i++){
      char c = SerialBuffer.charAt(i);
   //  line( i, height, i, height-c);
    }
  }
}

Viewing all articles
Browse latest Browse all 1768

Trending Articles