Я пытаюсь разобрать xml-файл с URL-адреса и получить значения Lat в файле и просто отобразить их в файле тосты для отладки. Я получаю эту ошибку: «Невозможно создать обработчик внутри потока, который не под названием Looper.prepare()»Android AsyncTask Error [Не удается создать обработчик внутри потока, который не вызвал Looper.prepare()]
Это код, который я сейчас использую:
public void getGpx(String area) {
final String area2 = area;
new GHAsyncTask<Void, Void, List<String>>() {
protected List<String> saveDoInBackground(Void... params)
throws Exception {
String urlString = fileListURL + area2 + ".gpx";
logUser(urlString);
ArrayList testingXml = null;
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(conn.getInputStream());
NodeList nodes = doc.getElementsByTagName("trkpt");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList title = element.getElementsByTagName("lat");
Element line = (Element) title.item(0);
testingXml.add(line.getTextContent());
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
} catch (ParserConfigurationException a) {
}
return testingXml;
}
@Override
protected void onPostExecute(List<String> gpxList) {
if (hasError()) {
getError().printStackTrace();
logUser("Are you connected to the internet? Problem while fetching remote area list: "
+ getErrorMessage());
return;
} else if (gpxList == null || gpxList.isEmpty()) {
logUser("something went wrong");
return;
}
logUser(gpxList.toString());
}
}.execute();
}
Я надеюсь, кто-то может помочь мне исправить эту ошибку. В коде могут быть и другие ошибки, которые я еще не нашел. Просто новобранец пытается собрать это вместе.
Я упускал из виду logUser() наверху, это вызывало тосты. Благодаря! –