Thanks to visit codestin.com
Credit goes to github.com

Skip to content

NullPointer exception on running sketch on processing #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cjdg opened this issue Jun 6, 2018 · 4 comments · Fixed by #10
Closed

NullPointer exception on running sketch on processing #1

cjdg opened this issue Jun 6, 2018 · 4 comments · Fixed by #10

Comments

@cjdg
Copy link

cjdg commented Jun 6, 2018

Im havin a lot of errors on Processing 3, some are nullpointer exceptions and map(NaN, 20, 40, 240, 360) called, which returns NaN (not a number)

@juichi
Copy link

juichi commented Jun 23, 2018

I found that adding a small delay after the check to see if serial data was available stopped the NullPointer exception. I do not have any idea why it fixed it and I think it is a kludge. My thinking is that there is something messy with the Processing 3 Serial handler, my computer or something. I also ran this on an Wemos mini Lite so maybe that is a factor. Oh I also changed my null terminator in the arduino code to '\0' to try to fix this, that is why I have a readStringUntil(00). The initial code has 13 which is carriage return.

See below:
if(myPort.available() > 64){
delay(40); <---- add this.
myString = myPort.readStringUntil(00) ;

@jmorsap
Copy link

jmorsap commented Dec 30, 2018

I have experienced the same problem with Processing 3. I added a little check to make sure that the string is not empty before doing anything else in the draw() function.

if (myString !=null)
{
  String splitString[] = splitTokens(myString, ",");
  
......

Seems to solve it, but I have no idea why the string would be empty after the myString = myPort.readStringUntil(13); command. I haven't used processing very much. Would the next line execute before the readStringUntil function has completed?

@jmorsap
Copy link

jmorsap commented Jan 1, 2019

FYI, looks like the issue is with the line
if(myPort.available() > 64){

There's actually something closer to 300 bytes available before the carriage return character is sent, but I think this varies as the data is sent as a string of floats, which I think can have different numbers of characters in the decimal value, so the length of bytes in the float string might change depending on what the data looks like.

A better way for the code to be written might be to use something that reads each character as it comes in, adds it to a buffer, and checks if the character is the string terminator.

      if (myPort.available()>0)
      {
      mybuff[i] = myPort.read();
i++; //I needs to be global
}
if(mybuff[i] == 13)
{
i = 0;
//parse the data out
//update the pixels
}

@PaulZC
Copy link
Contributor

PaulZC commented Oct 19, 2022

Hi @cjdg @juichi @jmorsap ,

Thank you for raising this issue - and apologies for the VERY slow reply!

I've merged @Suisse00 's PR #4 into v1.0.2. v1.0.2 will be released shortly. I know it has been years since this issue was opened, but please do give v1.0.2 a try and let me know if you see any other issues.

Very best wishes,
Paul

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants