기본적으로 내 앱을 실행하면 충돌이 발생하거나 텍스트 나 기타 내용이 표시되지 않습니다. 내 주요 활동에 조각과 viewPager를 사용하고 있지만, 문제의 원인이되는 클래스는 하나입니다Jsoup 및 setText가 Android에서 작동하지 않습니다.
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 명의 다른 이들에게 복사하여 닫으십시오. – njzk2
http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception –
이 다운로드 링크가 마음에 들지 않습니까? becos 스레드가 닫혀 있습니다. http://wl.filegenie.com /~ikp4success/AnswerJsoup.txt – ImGeorge