Processing error


hello,

i use following code send image c328 camera processing.

i following error: nullpointerexeption

i use following processing code:

code: [select]

import processing.serial.*;

serial myport;
int = 1;

string imagefilename = "photo_" + year() + "_" + day() + "_" + month() + "-" + hour() + "_" + minute() + "_" + second() + "_" + millis() + ".jpg";
int chare = 69;
int charo = 79;
int charf = 70;
int totalbytes = 0;

byte[] photo = {
};

void setup()
{
 //set , open serial port
 println( serial.list() );
 myport = new serial( this, serial.list()[1], 9600 );
 myport.clear();
}

void draw()
{
 // import picture
 byte[] buffer = new byte[64];

 while( myport.available() > 0 )
 {
   int readbytes = myport.readbytes(buffer);

   //print( "read " );
   //print( readbytes );
   //println( " bytes ..." );

   for( int = 0; < readbytes; i++ )
   {

     totalbytes = totalbytes + 1;

     //print( "read " );
     //print( totalbytes );
     //println( " bytes in total ..." );

     photo = append( photo, buffer[i] );

     print( "photoarray contains: " );
     print(photo.length);
     println( " elements..." );

     if ( totalbytes > 2 && photo[totalbytes-3] == chare && photo[totalbytes-2] == charo && photo[totalbytes-1] == charf ){

       // save picture file
       if( photo.length > 0 ) {
         print( "writing disk " );
         print( photo.length );
         println( " bytes ..." );
         savebytes( imagefilename, photo );
         println( "done!" );

         // open picture
         size(6400, 4800);
         pimage c328image;
         c328image = loadimage(imagefilename);
         image(c328image, 0, 0);

         //clear array
         photo = null; // clear array

         //clear totalbytes
         totalbytes = 0;

         //flush serial port
         myport.clear();

         return;

       }
     }
   }
 }
}


the error executed on line when new picture imported (2nd cycle):

code: [select]

photo = append( photo, buffer[i] );


probably problem due fact try clear array using line of code:

code: [select]

photo = null; // clear array ????


is problem?

thanks in advance,

cheers.

if java.. (probably is), you're throwing away object, opposed resetting it.
does array have .clear() method?


Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > Processing error


arduino

Comments