处理 - BufferedOutputStream异常

I'm a stranger to Java, but I'm developing an app with Processing, and I need enlightenment, please.

I'm running a php server on 127.0.0.1:8080 on the root of the .pde below. all my php scripts are bug free, as well as the rest of the Processing code.

after careful analysis, I've learned that the bug is in the function below.

what is the raised exception down under telling me? and how can I fix the code?

//(cont)

void postPicture(){
//load the saved image into an array of bytes
byte[] thisFile=loadBytes(fileName);

//open a new connection to the server
thisClient = new Client(this, "localhost", 80);
//make an HTTP POST request:
thisClient.write("POST " + pictureScriptUrl + " HTTP/1.1
");
thisClient.write("Host: localhost
");
//tell the server you're sending the POST in multiple parts
//and send a unique string that will delineate the parts
thisClient.write("Content-Type: multipart/form-data; boundary=");
thisClient.write(boundary + "
");

//form the beginning of the request
String requestHead ="--" + boundary + "
";
requestHead +="Content-Disposition: form-data; name=\"file\"; ";
requestHead += "filename=\"" + fileName + "\"
";
requestHead +="Content-Type: image/jpeg

";

//form the end of the request
String tail="

--" + boundary + "--
";

//calculate and send the length of the total request
//including the head of the request, the file, and the tail
int contentLength = requestHead.length() + thisFile.length + tail.length();
thisClient.write("Content-Length: " + contentLength + "

");

//send the header of the request, the file and the tail
thisClient.write(requestHead);
thisClient.write(thisFile);
thisClient.write(tail);
}

java.lang.NullPointerException
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at javax.imageio.stream.FileCacheImageOutputStream.close(FileCacheImageOutputStream.java:238)
at com.sun.imageio.stream.StreamCloser$CloseAction.performAction(StreamCloser.java:130)
at com.sun.imageio.stream.StreamCloser$1.run(StreamCloser.java:74)
at java.lang.Thread.run(Thread.java:745)