Java 正在处理-BufferedOutputStream异常

Java 正在处理-BufferedOutputStream异常,java,php,network-programming,processing,Java,Php,Network Programming,Processing,我对Java不太熟悉,但我正在开发一款带有处理功能的应用程序,我需要一些启发 我正在127.0.0.1:8080上运行php服务器,位于下面.pde的根目录下。我所有的php脚本以及其余的处理代码都没有bug 经过仔细分析,我了解到错误在下面的函数中 下面引发的异常告诉我什么?我如何修复代码 //(cont) void postPicture(){ //load the saved image into an array of bytes byte[] thisFile=loadBytes(f

我对
Java
不太熟悉,但我正在开发一款带有
处理功能的应用程序,我需要一些启发

我正在
127.0.0.1:8080
上运行
php服务器
,位于下面
.pde
的根目录下。我所有的
php脚本
以及其余的处理代码都没有bug

经过仔细分析,我了解到错误在下面的函数中

下面引发的异常告诉我什么?我如何修复代码

//(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\n");
thisClient.write("Host: localhost\n");
//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 + "\n");

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

//form the end of the request
String tail="\n\n--" + boundary + "--\n";

//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 + "\n\n");

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


是哪一行导致了这个错误?@KevinWorkman我不知道,它是在处理过程中产生的;有没有办法检查准确的行?可能是每行前面的
println()
语句?要打印的最后一行是抛出NPE的那一行。你是如何发现这个方法是罪魁祸首的?我隔离了这些方法,而这个方法是唯一抛出它的方法。是什么导致了这个错误?@KevinWorkman我不知道,它是在处理过程中提出的;有没有办法检查准确的行?可能是每行前面的
println()
语句?要打印的最后一行是抛出NPE的那一行。你是怎么发现这个方法是罪魁祸首的?我隔离了这些方法,只有这个方法扔了它。
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)