我正在尝试将此代码放入一个onStart
方法中。我尝试了几件事,但似乎找不到方法......如果我把它放在一个onStart
方法上,错误是:
无法从具有 void 结果类型的方法返回值
我确实尝试将其更改为 int,有什么想法吗?
我尝试做public int onStart...
方法,但效果不佳
注意:我是 Android 新手,这对你来说似乎是一个明显的答案,但不幸的是对我来说不是。
提前致谢!!
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;
}