0
I’m creating an app for Android with Android Studio and I’m having trouble reading a text file that is hosted on the Internet. Whenever I try to execute the method checkVersion() it returns the following error:
The message is empty because net.getMessage()
is returning null
iPoema.java
public int getVersion() {
int versao = 0;
String linha = "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;
}
Depending on the system used and the HTTP version, you may not be giving the required minimum information (I don’t know Java very well).
– user2692