I'm really new to processing and I am trying to use serial processing but I keep getting this error. I am trying to use code from the gizmologi.st
Here is the code just in case:
Code:import processing.serial.*;
Serial myPort;
String filename = "photo.jpg";
byte[] photo = {};
Boolean readData = false;
void setup()
{
println( Serial.list() );
myPort = new Serial( this, Serial.list()[0], 38400 );
}
void draw()
{
byte[] buffer = new byte[64];
if( readData )
{
while( myPort.available() > 0 )
{
int readBytes = myPort.readBytes( buffer );
print( "Read " );
print( readBytes );
println( " bytes ..." );
for( int i = 0; i < readBytes; i++ )
{
photo = append( photo, buffer[i] );
}
}
}
else
{
while( myPort.available() > 0 )
{
print( "COM Data: " );
println( myPort.readString() );
}
}
}
void keyPressed()
{
if( photo.length > 0 ) {
readData = false;
print( "Writing to disk " );
print( photo.length );
println( " bytes ..." );
saveBytes( filename, photo );
println( "DONE!" );
}
else {
readData = true;
myPort.clear();
println( "Waiting for data ..." );
}
}
I keep getting this error when trying to compile:
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
processing.app.debug.RunnerException: ArrayIndexOutOfBoundsException: 0
at processing.app.Sketch.placeException(Unknown Source)
at processing.app.debug.Runner.findException(Unknown Source)
at processing.app.debug.Runner.reportException(Unknown Source)
at processing.app.debug.Runner.exception(Unknown Source)
at processing.app.debug.EventThread.exceptionEvent(Unknown Source)
at processing.app.debug.EventThread.handleEvent(Unknown Source)
at processing.app.debug.EventThread.run(Unknown Source)
Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 0
at Arduino_to_Computer.setup(Arduino_to_Computer.java:32)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
I'm a big time newby and any help is greatly appreciated!