if(post_data != null && bufferedWriter != null)
{
bufferedWriter.write(post_data);
}
if anyone of them is null, it shouldn't even execute! but it still executes and throws an error.
Everyone was focused on the wrong problem.I solved the error: I just moved the initialization and close inside the write and read functions as follows:
public void write(String post_data) throws IOException {
outputStream = httpURLConnection.getOutputStream();
bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
}
public String read() throws IOException {
inputStream = httpURLConnection.getInputStream();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String result="", line;
while((line = bufferedReader.readLine()) != null){
result += line;
}
bufferedReader.close();
inputStream.close();
return result;
}