I'm using this codes in asynctask for load data from URL. I added internet permissions in manifest.xml, I haven't any errors on Android Studio but when i debugging application, going crash. Where is my fault?
protected Void doInBackground(Void... params) {
try {
URL url = new URL("my_url");
connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
jsonString = buffer.toString();
if(connection != null) { connection.disconnect(); }
try {
if(reader != null) { reader.close(); }
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
Thanks..