【发布时间】:2015-01-18 17:50:26
【问题描述】:
这是我的调试堆栈:
Thread [<1> main] (Suspended (exception IllegalArgumentException))
<VM does not provide monitor information>
HttpConnection.connect(String) line: 30
Jsoup.connect(String) line: 73
Parsing.doInBackground(String...) line: 23
MainActivity$1.onClick(View) line: 29
Button(View).performClick() line: 4424
View$PerformClick.run() line: 18383
Handler.handleCallback(Message) line: 733
ViewRootImpl$ViewRootHandler(Handler).dispatchMessage(Message) line: 95
Looper.loop() line: 137
ActivityThread.main(String[]) line: 4998
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 515
ZygoteInit$MethodAndArgsCaller.run() line: 777
ZygoteInit.main(String[]) line: 593
这是我的代码:
package com.example.pricetracker;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import android.os.AsyncTask;
public class Parsing extends AsyncTask<String,Void,String> {
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
Document htmlFile = null;
Element price = null;
try {
htmlFile = Jsoup.connect("www.amazon.in/Google-Nexus-D821-16GB-Black/dp/B00GC1J55C/ref=sr_1_1?s=electronics&ie=UTF8&qid=1421161258&sr=1-1&keywords=Google").get();
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
catch (Exception ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
try{
if( htmlFile.getElementById("priceblock_ourprice")!= null)
{
price = htmlFile.getElementById("priceblock_ourprice");
}
else
{
price = htmlFile.getElementById("priceblock_saleprice");
}
}catch(Exception e)
{
e.printStackTrace();
}
return (String)price.toString();
}
如何从 URL 中获取数据?
这个问题的原因是什么,我该如何解决?
我被困在这里超过一天。
大家有什么想法吗?提前致谢。
【问题讨论】:
标签: java android eclipse exception jsoup