我想在 android 中使用 Jsoup 从网页中删除一些文本。我使用了这些代码:
package com.example.scrappping1;
import java.io.IOException;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView text = (TextView)findViewById(R.id.tv);
String URL = "http://www.bengalinux.org/cgi-bin/abhidhan/index.pl?en_word=like";
Document site = null;
try
{
site = Jsoup.connect(URL).userAgent("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de-de) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10").get();
}
catch (IOException e)
{
//e.printStackTrace();
Toast.makeText(getApplicationContext(), "fdf",Toast.LENGTH_LONG).show();
}
Elements newsline = site.select("div.dict_entry");
String output = "";
for (int i = 0; i < newsline.size(); i++) {
output = newsline.get(i).text();
}
text.setText(output);
}// onCreate
}// end
但我收到了这个错误
“应用程序意外停止”
我不明白为什么?我该如何解决这个问题?