我正在 android studio中创建一个项目。我从 sql server 数据库中检索信息时收到此错误。我正在使用 .php 文件进行数据库连接。在调试时我发现以下行生成错误:
inputStream = urlConnection.getInputStream();
请参阅我的代码
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;