我正在尝试检索网站的 html 代码并对其进行解析以获取该网站的文本。出于某种原因,当我注释掉代码的 jsoup 库部分时,我下面的类运行良好,但否则我会收到这个奇怪的错误“找不到源代码”,并且调试部分没有遇到任何断点。甚至没有任何 jsoup 代码之前的那些。只要我点击模拟器上的按钮,它就会直接跳到错误。我在我的 java 构建路径中将 jsoup jar 文件作为外部 JAR 添加到我的 eclipse 项目中。我究竟做错了什么?
顺便说一句:我有 jsoup 1.6.2
public class AndroidActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText eText = (EditText) findViewById(R.id.address);
final TextView tView = (TextView) findViewById(R.id.pagetext);
// TODO Auto-generated method stub
class TareaAsincrona extends AsyncTask<String, Void ,String>
{
@Override
protected void onPreExecute()
{
}
@Override
protected void onPostExecute(String X)
{
}
@Override
protected String doInBackground(String... urls)
{
try
{
// Perform action on click
URL url = new URL(eText.getText().toString());
URLConnection conn = url.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = "";
String Codigo_Fuente ="";
while ((line = rd.readLine()) != null)
{
Codigo_Fuente= Codigo_Fuente + line;
//Codigo_Fuente.add(line);//android.text.Html.fromHtml(line).toString());
}
Document doc = Jsoup.parse(Codigo_Fuente);
return doc.body().text();
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
}
final Button button = (Button) findViewById(R.id.ButtonGo);
button.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View arg0)
{
new TareaAsincrona().execute();
}
});
}
}