Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving problems parsing mens health RSS on android
    primarykey
    data
    text
    <p>I'm trying to parse an RSS feed from mens health using the document builder. It isn't working and when I debug I don't get an error. I think the issues lies with the element lines, as I don't really understand if I'm getting the correct values. Here is my code:</p> <pre><code>private void refreshTips(){ //Get the XML URL url; try { String tipFeed = getString(R.string.tip_feed); url = new URL(tipFeed); URLConnection connection; connection = url.openConnection(); HttpURLConnection httpConnection = (HttpURLConnection)connection; int responseCode = httpConnection.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_OK){ InputStream in = httpConnection.getInputStream(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); //Parse the menshealth feed Document dom = db.parse(in); Element docEle = dom.getDocumentElement(); //Clear the old tips tips.clear(); //Get a list of each tip entry NodeList nl = docEle.getElementsByTagName("item"); if(nl != null &amp;&amp; nl.getLength() &gt;0){ for(int i=0; i &lt; nl.getLength(); i++){ Element item = (Element)nl.item(i); Element title = (Element)item.getElementsByTagName("title").item(0); Element link = (Element)item.getElementsByTagName("link").item(0); Element details = (Element)item.getElementsByTagName("description").item(0); Element when = (Element)item.getElementsByTagName("pubDate").item(0); String _title = title.getNodeValue(); String _link = link.getNodeValue(); String _det = details.getNodeValue(); String _date = when.getNodeValue(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'"); Date tDate = new GregorianCalendar(0,0,0).getTime(); try{ tDate = sdf.parse(_date); }catch(ParseException e){ e.printStackTrace(); } catch (java.text.ParseException e) { e.printStackTrace(); } Tip tip = new Tip(tDate, _title, _det, _link); addNewTip(tip); } } } }catch(MalformedURLException e){ e.printStackTrace(); }catch(IOException e){ e.printStackTrace(); }catch(ParserConfigurationException e){ e.printStackTrace(); }catch(SAXException e){ e.printStackTrace(); } finally { } } private void addNewTip(Tip tip){ tips.add(tip); aa.notifyDataSetChanged(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload