I'm trying to put this code in a onStart
method. I tried several things but can't seem to find a way... if I put it on a onStart
method the error is:
cannot return value from a method with a void result type
I did try changing it into a int, any ideas?
I tried to do public int onStart...
method, but didn't work out very well
Note: I'm to new to Android, this my seem a obvious answer to you, but unfortunately not to me.
thanks in advance!!
public String getGiphyViews() {
String id_image = "qi6Yrko";
String source = "";
try {
URL url = new URL("http://imgur.com/" + id_image);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
StringBuilder str = new StringBuilder();
String line;
while((line = reader.readLine()) != null) {
if (line.contains("views")) {
str.append(line);
}
}
in.close();
source = str.toString();
} catch (IOException e) {
e.printStackTrace();
}
String views = source.split("<span class=\"views-" + id_image + "\">")[1].split("<")[0];
TextView t = (TextView) findViewById(R.id.views);
assert t != null;
t.setText(views);
return views;
}