We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Null pointer exception
Page Index Toggle Pages: 1
Null pointer exception (Read 709 times)
Null pointer exception
Apr 13th, 2009, 9:51am
 
Why do I keep getting this error "null pointer exception"?

Code:

import processing.serial.*;
Serial myPort;
String inString;
int[] Data;

PFont font;

void setup()
{
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.clear();
//myPort.bufferUntil(59);
inString = myPort.readStringUntil(59);
inString = null;
font = loadFont("ArialMT-16.vlw");
size(100,100);
}

void draw()
{
MyData();
textFont(font);
fill(0,0,0);
text(Data[0],20,20);
}

void MyData()
{
inString = myPort.readStringUntil(59);
println(inString);
Data = int(split(inString,","));
println(Data[0]);
println(Data[1]);
println(Data[2]);
println(Data[3]);
println(Data[4]);
println(Data[5]);
println(Data[6]);
println(Data[7]);
println(Data[8]);
println(Data[9]);
println(Data[10]);
println(Data[11]);
println(Data[12]);
println(Data[13]);
println(Data[14]);
println(Data[15]);
println(Data[16]);
}


Thanks
Re: Null pointer exception
Reply #1 - Apr 13th, 2009, 11:03am
 
I think it is because the call to readStringUntil didn't find anything.

Read the description from:

http://processing.org/reference/libraries/serial/Serial_readStringUntil_.html

You can test for null before doing the split and printing.
Re: Null pointer exception
Reply #2 - Apr 13th, 2009, 2:40pm
 
Did you save your file under a new name?

if yes maybe your ArialMT file is missing.
Re: Null pointer exception
Reply #3 - Apr 13th, 2009, 6:26pm
 
NoahBuddy wrote on Apr 13th, 2009, 11:03am:
I think it is because the call to readStringUntil didn't find anything.

Read the description from:

http://processing.org/reference/libraries/serial/Serial_readStringUntil_.html

You can test for null before doing the split and printing.


Thanks, I'm still learning how unforgiving this lang is.
Page Index Toggle Pages: 1