我在android studio中使用JSoup。在我的代码,我有这样的:JSoup从String到Int
Elements description = document.select("something");
如果我这样做 -
String foo = description.text();
一切工作正常。
但如果我这样做 -
int y = Integer.parseInt(description.text());
为什么我的应用程序崩溃?
我的所有代码:
public Void doInBackground(Void... params) {
try {
// Connect to the web site
Document document = Jsoup
.connect("something")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko")
.get();
Elements description = document.select("something");
String foo = description.text();
int fuu = Integer.parseInt(foo);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
发布错误。 –
wild guess:description.text()不是有效整数 – Reimeus
Try:Integer.parseInt(description.text()。toString()); –