Ошибка разбора соты XML

У меня есть файл XML, который анализируется DocumentBuilderна телефонах он правильно разбирает, но планшет выдает исключение. Я читал, и было предложено использовать AsyncTaskЯ реализовал это, и это все еще не анализирует. Кто-нибудь знает об этой проблеме или что нужно сделать, чтобы ее исправить. Ниже мой код.

AsyncTask

@Override
protected void onCreate(Bundle savedInstanceState) {
DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[] { "url" });
}
 private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        //String response = "";
        for (String url : urls) {
            HttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet(url);

            HttpResponse responseGet = null;
            try {
                responseGet = httpclient.execute(httpget);
                final int status = responseGet.getStatusLine().getStatusCode();
                if (status != HttpStatus.SC_OK) {
                    // give message
                //  Log.i("Error", "No Connection");
                }
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                  e.printStackTrace();
                  //Log.i("caught error","ClientException");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                  e.printStackTrace();
                //  Log.i("caught error","IOException");
            }
            //String responseBody = null;
            try {
                responseBody = EntityUtils.toString(responseGet.getEntity());
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                  e.printStackTrace();
                //  Log.i("caught error","ClientException");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                  e.printStackTrace();
                //  Log.i("caught error","IOException");
            }
        }

        return responseBody;
        }

Вот где я звоню по этому адресу:

       @Override
    protected void onPostExecute(String result) {
    //  Log.i("returndata",result);


          ArrayList<String> custCount = new ArrayList<String>();
          ArrayList<String> custMinMax = new ArrayList<String>();
          ArrayList<String> hexcode = new ArrayList<String>();
          List<HashMap<String, String>> colorData = new LinkedList<HashMap<String, String>>();


          try {
              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
              DocumentBuilder db = dbf.newDocumentBuilder();
             //encode the xml to UTF -8
              ByteArrayInputStream encXML = new ByteArrayInputStream(result.getBytes("UTF8"));

              Document doc = db.parse(encXML);
              doc.getDocumentElement().normalize();
              Log.i("XML parsing OK","ok");
       try { 
              NodeList nodeList = doc.getElementsByTagName("Section");
              NodeList nameList = null;
              for (int cc = 0; cc < nodeList.getLength(); cc++) {

                  Node custcountNode = nodeList.item(cc);

                  Element custcountElement = (Element) custcountNode;
                  NodeList custcountList = custcountElement
                          .getElementsByTagName("custcount");
                  Element custcountnameE = (Element) custcountList.item(0);
                  custcountList = custcountnameE.getChildNodes();

                  custcount = ((Node) custcountList.item(0))
                          .getNodeValue();
                  custCount.add(new String(custcount));

              }

              for (int i = 0; i < nodeList.getLength(); i++) {
                  rectOptions = new PolygonOptions();
                  Node node = nodeList.item(i);

                  Element locElement = (Element) node;
                  nameList = locElement
                          .getElementsByTagName("coords");

                  int curCustCount = Integer.valueOf(custCount.get(i));

                  for (int z = 0; z < colorData.size(); z++) {
                      int custmin = Integer.valueOf(colorData.get(z).get(
                              "custmin"));
                      int custmax = Integer.valueOf(colorData.get(z).get(
                              "custmax"));

                      if (curCustCount >= custmin && curCustCount <= custmax) {
                          curColor = (colorData.get(z).get("hexcode"));

                          break;
                      }

                  }

                  points = new ArrayList<String[]>();


                  for (int j = 0; j < nameList.getLength(); j++) {

                      Node nodel = nameList.item(j);

                      Element fstElement = (Element) nodel;

                      NodeList nameL = fstElement.getElementsByTagName("coords");
                      Element nameE = (Element) nameL.item(0);


                      nameL = nameE.getChildNodes();

                      String latit = ((Node) nameL.item(0)).getNodeValue();



                      String[] latt = latit.split(",");

                      points.add(latt);
                 }
                     // Do something here with points

          }
                    } 
                      catch (Exception e){
                      e.printStackTrace();

                 }
          }  
                   catch (Exception e) {
                   e.printStackTrace();
           }
    }

Это формат мой XML

   <Section>
    <custcount>3</custcount>
    <location>
       <coords>35.25010,-90.08342</coords>
       <coords>35.29177,-90.08342</coords>
       <coords>35.29177,-90.04175</coords>
       <coords>35.25010,-90.04175</coords>
       <coords>35.25010,-90.08342</coords>
   </location>
 </Section>
<Section>
    <custcount>3</custcount>
    <location>
       <coords>35.25040,-90.08342</coords>
       <coords>35.29477,-90.08342</coords>
       <coords>35.29477,-90.04173</coords>
       <coords>35.25010,-90.04175</coords>
       <coords>35.25010,-90.08342</coords>
   </location>
 </Section>                 

Это мои результаты трассировки стека:

  01-31 09:50:07.541: W/System.err(21462): java.lang.NullPointerException
  01-31 09:50:07.541: W/System.err(21462):  at com.mlgw.map.MainActivity2$DownloadWebPageTask.onPostExecute(MainActivity2.java:381)
  01-31 09:50:07.541: W/System.err(21462):  at com.mlgw.map.MainActivity2$DownloadWebPageTask.onPostExecute(MainActivity2.java:1)
  01-31 09:50:07.541: W/System.err(21462):  at android.os.AsyncTask.finish(AsyncTask.java:590)
  01-31 09:50:07.541: W/System.err(21462):  at android.os.AsyncTask.access$600(AsyncTask.java:149)
  01-31 09:50:07.541: W/System.err(21462):  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:603)
  01-31 09:50:07.541: W/System.err(21462):  at android.os.Handler.dispatchMessage(Handler.java:99)
  01-31 09:50:07.541: W/System.err(21462):  at android.os.Looper.loop(Looper.java:132)
  01-31 09:50:07.541: W/System.err(21462):  at android.app.ActivityThread.main(ActivityThread.java:4129)
  01-31 09:50:07.551: W/System.err(21462):  at java.lang.reflect.Method.invokeNative(Native Method)
  01-31 09:50:07.551: W/System.err(21462):  at java.lang.reflect.Method.invoke(Method.java:491)
  01-31 09:50:07.551: W/System.err(21462):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:855)
  01-31 09:50:07.551: W/System.err(21462):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:613)
  01-31 09:50:07.551: W/System.err(21462):  at dalvik.system.NativeStart.main(Native Method)

Похоже, что это происходит в строке 381, которая является моей координатой, она отлично работает на телефонах, но получает нулевое значение на планшетах.

Любые предложения о том, что необходимо добавить или изменить, будут оценены

2 ответа

Решение

Я нашел решение своей проблемы. Я в основном должен был повторить мой цикл, который хранил данные. Не знаю, почему оригинальный способ работал для телефонов, а не для планшета.

Узел узел = ProfileNode.item (gd);

NodeList nodeList = node.getChildNodes ();

String name = ((Node) (nodeList).item (0)). GetNodeValue();

Другие вопросы по тегам