I'm creating an Android app with Android Studio and am having trouble reading a text file that is hosted on the Internet. Whenever I try to execute the checkVersion () method it returns the following error:
Themessageisemptybecausenet.getMessage()
isreturningnull
iPoema.java
publicintgetVersion(){intversao=0;Stringlinha="0";
BufferedReader in = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet();
URI website = new URI("http://www.xadees.xpg.com.br/iPoema.txt");
request.setURI(website);
HttpResponse response = httpclient.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String sb;
while ((sb = in.readLine()) != null) {
linha += sb;
}
in.close();
versao = Integer.parseInt(linha);
} catch (NetworkOnMainThreadException net) {
showMessage(net.getClass().getName(), net.getMessage());
} catch (IOException io) {
showMessage(io.getClass().getName(), io.getMessage());
} catch (URISyntaxException use) {
showMessage(use.getClass().getName(), use.getMessage());
}
return versao;
}