【发布时间】:2013-12-09 19:51:05
【问题描述】:
基本上,当我执行我的应用程序时,它要么崩溃,要么不显示任何文本或任何内容。 我在我的主要活动中使用 Fragments 和 viewPager,但导致问题的类是这个:
public class DailyWord extends Fragment {
Document doc;
String data;
TextView t;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState) {
View mainView = inflater.inflate(R.layout.activity_daily_word, container, false);
try {
doc = Jsoup.connect("http://www.urbandictionary.com/").get();
} catch (IOException e) {
e.printStackTrace();
}
Element Worddata = doc.getElementsByClass("word").first();
Element Worddata2 = Worddata.select("a[href]").first();
String wordName = Worddata2.text();
Element definition = doc.getElementsByClass("description").first();
String define = definition.text();
Element example = doc.getElementsByClass("example").first();
String context = example.text();
data = ("Word:\n" + wordName + "\n" + "Definition\n" + define + "\n" + "Context:\n" + context);
t = (TextView) mainView.findViewById(R.id.textView1);
t.setText(data);
return mainView;
}
}
【问题讨论】:
-
发布堆栈跟踪。意识到这是一个 NetworkOnMainThreadException。将问题关闭为与其他 1000 人重复。
-
Do it like this download answer from this link can't answer it for you here becos thread is closed..wl.filegenie.com/~ikp4success/AnswerJsoup.txt
-
请先尝试搜索已经给出的相关问题的答案。如果没有找到,请提出您的问题
标签: java android textview jsoup settext