I want to get the content of a web directory using a php script, stored on the web server. This PHP Script I execute in an AsyncTask, here's the code:
protected ArrayList<String> doInBackground(String... urls) {
ArrayList<String> array = new ArrayList<String>();
try {
URL url = new URL("http:/www.example.org/folder/script.php");
BufferedReader br = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream()));
String line = null;
while((line = br.readLine()) != null){
array.add(line);
}
return array;
} catch (MalformedURLException e){
Log.e("error", e.getMessage());
return null;
} catch (IOException e){
Log.e("error", e.getMessage());
return null;
}
}
However, when the loop condition is fullfilled (line has the value "null") it instantly goes in the catch, but I don't even receive an exception.
I've also tried it with a for loop, same result.
String line = br.readLine();
for (; line != null ; ){
array.add(line);
line = br.readLine();
}
return array;
Any suggestions?