I am creating a project in android studio. I am getting this error while retrieving information from a sql server database. I am using .php files for database connection. On debugging I found that the following line is generating the error :
inputStream = urlConnection.getInputStream();
please see my code
private class ConnectToDatabaseMain extends AsyncTask<String, Void, Patient[]>
{
.....
protected XXXX[] doInBackground(String... params) {
// if (params.length == 0) return null; // Nothing to look up
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
InputStream inputStream;
StringBuffer buffer = new StringBuffer();
JSONObject jsonObject = new JSONObject();
String jsonString;
String serverUrl = params[0];
String date = params[1];
try {
// Create the request to the network database
URL url = new URL(serverUrl);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.connect();
jsonObject.put("date", date);
DataOutputStream printout = new DataOutputStream(urlConnection.getOutputStream());
printout.writeBytes(jsonObject.toString());
printout.flush();
printout.close();
// Read the input stream into a String
inputStream = urlConnection.getInputStream();
if (inputStream == null) return null;