NumberFormatException with Serial Communication

edited June 2014 in Questions about Code

I'm trying to get the values read off from an arduino but I get a number format exception at the line where the line 'val = Integer.parseInt(s);' occurs. What's going on?

import processing.serial.*;

Serial myPort;
String portName;
String s;
int val;

void setup(){
  size(displayWidth/2, displayHeight/2);
  portName = Serial.list()[2];
  myPort = new Serial(this, portName, 9600);
}

void draw(){
  s = myPort.readStringUntil('\n');
  if (s != null) {
    val = Integer.parseInt(s);
    println("giving val number");
  } 
  print("From " + portName + ": \n"); //print it out in the console
  //println("\"" + s + "\"");

  println(val);
}

Answers

Sign In or Register to comment.