I try to read a text file on a server. But i don’t have the test returned. Seems I have a Exception error.
How to see the error in eclipse, or displaying the error ?
If I try to log the erreor, the app go closed. (Log.e(“Exception —>”,e.getMessage());)
The code here after doent work.
public static String getText(String urlAdress) {
String text_file = "";
BufferedReader in = null;
try {
// create a url object
URL url = new URL(urlAdress);
// create a urlconnection object
URLConnection urlConnection = url.openConnection();
// Read all the text returned by the server
in = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline
// character(s)
text_file = text_file + str;
}
in.close();
} catch (MalformedURLException e) {
text_file = "error";
Log.e("MalformedURLException --->", e.getMessage());
} catch (IOException e) {
text_file = "error";
Log.e("IOException --->", e.getMessage());
} catch (Exception e) {
text_file = "error";
// Log.e("Exception --->",e.getMessage());
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
Log.e("finally IOException --->",
"Exception trying to close BufferedReader");
}
}
}
return text_file;
}
Any Idea ?
Thanks,
So, take a look at this. This means you need to move all that code from main thread to another thread.