-4
파서는 괜찮지 만 asynctask의 컨텍스트에 넣으면 IOE 예외가 발생합니다. 어떻게해야합니까?비동기 발신자에게 무슨 문제가 있습니까?
private class AsyncCaller extends AsyncTask<Void, Void, List<DummyContent.DummyItem>> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// This method will be running on UI thread
}
@Override
protected List<DummyContent.DummyItem> doInBackground(Void... params) {
// This method will be running on background thread so don't update UI from here
// Do your long running http tasks here and you can access the parent class' variable url over here
List<DummyContent.DummyItem> list = new ArrayList<>();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
DummyContent.UNAME, DummyContent.PASSWORD.toCharArray());
}
});
try {
DummyContentRegistry registry = new XMLDummyContentParser(DummyContent.url).parse();
for (DummyContent.DummyItem t: registry.getTeachers()) {
list.add(t);
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception should not have been thrown");
}
return list;
}
@Override
protected void onPostExecute(List<DummyContent.DummyItem> result) {
super.onPostExecute(result);
// This method will be running on UI thread
for (int i = 1; i <= DummyContent.COUNT; i++) {
DummyContent.addItem(DummyContent.createDummyItem(i));
}
for (DummyContent.DummyItem t: result) {
DummyContent.addItem(t);
}
}
}
그동안 내가있어 스택 추적 :
08-07 21:34:43.264 26425-26775/ca.ubc.econ.montoya3.myapplication E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
Process: ca.ubc.econ.montoya3.myapplication, PID: 26425
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.AssertionError: Exception should not have been thrown
at org.junit.Assert.fail(Assert.java:88)
at ca.ubc.econ.montoya3.myapplication.MainActivity$AsyncCaller.doInBackground(MainActivity.java:236)
at ca.ubc.econ.montoya3.myapplication.MainActivity$AsyncCaller.doInBackground(MainActivity.java:208)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
내가하고 싶지는 탭 활동 목록 조각을 업데이트하는 것입니다? 실패없이 ... 내가 뭔가를 내가 전에 생각했던 좋아하지
08-07 23:53:58.161 2567-3115/ca.ubc.econ.montoya3.myapplication W/System.err: java.io.IOException: Couldn't open https://oceanandcrow.ca/android/XML/Teachers
08-07 23:53:58.168 2567-3115/ca.ubc.econ.montoya3.myapplication W/System.err: Caused by: java.net.UnknownHostException: Unable to resolve host "oceanandcrow.ca": No address associated with hostname
08-07 23:53:58.169 2567-3115/ca.ubc.econ.montoya3.myapplication W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
원래 오류가 표시 될 수 있도록 오류를 제거하십시오. 이것은 우리에게 전혀 도움이되지 않습니다. –
@GabeSechan 업데이트 됨 – Student