DOM parsing error in RSS FEED -


i need parse xml file , need display in list view got problem while running code. 1 please me on come problem thank in advance

this xml file source http://purl.org/dc/elements/1.1/" version="2.0"

<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">   <channel>     <title>mobilenations</title>     <description>       mobile nations brings best of android central, crackberry.com, precentral.net, tipb.com, , wpcentral     </description>     <link>http://www.mobilenations.com/</link>     <language>en-us</language>     <lastbuilddate>wed, 07 aug 2013 06:15:01 -0400</lastbuilddate>     <pubdate>wed, 07 aug 2013 06:15:01 -0400</pubdate>     <item>       <title>         at&t activates new 4g lte markets, expands coverage in others       </title>       <description>         <p class="rtecenter"><img alt="at&amp;t" class="lightbox2 imagecache-w680h550 aligncenter" src="http://cdn.androidcentral.com/sites/androidcentral.com/files/imagecache/w680h550/postimages/108579/att-store-2.jpg" /></p> <h3> 6 new markets, expanded coverage in washington, d.c. , san francisco areas</h3> <p><a href="http://www.androidcentral.com/tags/att" title="at&amp;t">at&amp;t</a> sends word it&#39;s switched on 4g lte service in 6 new markets, while expanding coverage in 2 major cities.</p> <p>from today, at&amp;t lte&nbsp;should available in&nbsp;&mdash;</p> <p><a href="http://www.androidcentral.com/att-activates-new-4g-lte-markets-expands-coverage-others" target="_blank">read more</a></p>       </description>       <link>         http://www.androidcentral.com/att-activates-new-4g-lte-markets-expands-coverage-others       </link>       <pubdate>wed, 07 aug 2013 09:48:24 +0000</pubdate>       <category domain="http://www.androidcentral.com/articles/news">news</category>       <category domain="http://www.androidcentral.com/tags/4g">4g</category>       <category domain="http://www.androidcentral.com/tags/att-0">at&t</category>       <category domain="http://www.androidcentral.com/tags/lte">lte</category>       <guid ispermalink="false">32622 @ http://www.androidcentral.com</guid>       <comments>         http://www.androidcentral.com/att-activates-new-4g-lte-markets-expands-coverage-others#comments       </comments>       <dc:creator>alex dobie</dc:creator>     </item> 

my dom parser code is

package com.wfwf.everestnewsapp.parser;  import java.net.malformedurlexception; import java.net.url;  import javax.xml.parsers.documentbuilder; import javax.xml.parsers.documentbuilderfactory;  import org.jsoup.jsoup; import org.jsoup.select.elements; import org.w3c.dom.document; import org.w3c.dom.node; import org.w3c.dom.nodelist; import org.xml.sax.inputsource;  import android.util.log;  public class domparser {      private rssfeed _feed = new rssfeed();      public rssfeed parsexml(string xml) {          url url = null;         try {             url = new url(xml);         } catch (malformedurlexception e1) {             e1.printstacktrace();         }          try {             // create required instances             documentbuilderfactory dbf;             dbf = documentbuilderfactory.newinstance();             documentbuilder db = dbf.newdocumentbuilder();              // parse xml             document doc = db.parse(new inputsource(url.openstream()));             doc.getdocumentelement().normalize();              // <item> tags.             nodelist nl = doc.getelementsbytagname("item");             int length = nl.getlength();              log.i("this test message"+length, xml);             (int = 0; < length; i++) {                 node currentnode = nl.item(i);                 rssitem _item = new rssitem();                  nodelist nchild = currentnode.getchildnodes();                 int clength = nchild.getlength();                  log.i("this test message total child nodes"+clength, xml);                 // required elements each item                 // ishwor changed code j=0 , j= j+1                 (int j = 0; j < clength; j = j + 1) {                     log.i("first child node name is"+nchild.item(j).getnodename(), xml);                      node thisnode = nchild.item(j);                     string thestring = null;                       //ishwor changed                     if (thisnode != null && thisnode.getfirstchild() != null) {                         thestring = thisnode.getfirstchild().getnodevalue();                     }                     if (thestring != null) {                          string nodename = thisnode.getnodename();                            /*                       string nodename = thisnode.getnodename();                      //thestring = nchild.item(j).getfirstchild().getnodevalue();                      if(nchild.item(j).getfirstchild().getnodevalue()!=null){                     //if (thestring != null) {                         //string nodename = thisnode.getnodename();                            */                         if ("title".equals(nodename)) {                             // node name equals 'title' set node                             // value title in rssitem.                             _item.settitle(thestring);                              log.i("this test message"+thestring, xml);                          }                          else if ("description".equals(nodename)) {                             _item.setdescription(thestring);                              log.i("this test message"+thestring, xml);                              // parse html description image url                             string html = thestring;                             org.jsoup.nodes.document dochtml = jsoup.parse(html);                             elements imgele = dochtml.select("img");                             _item.setimage(imgele.attr("src"));                         }                          else if ("pubdate".equals(nodename)) {                              // replace plus , zero's in date                             // empty string                             string formateddate = thestring.replace(" +0000",                                     "");                             _item.setdate(formateddate);                         }                      }                 }                  // add item list                 _feed.additem(_item);             }          } catch (exception e) {         }          // return final feed once items added rssfeed         // object(_feed).         return _feed;     }  } 

my log cat error is

08-08 12:52:55.059: w/dalvikvm(3484): threadid=11: thread exiting uncaught exception (group=0x41a692a0) 08-08 12:52:55.064: e/androidruntime(3484): fatal exception: asynctask #1 08-08 12:52:55.064: e/androidruntime(3484): java.lang.runtimeexception: error occured while executing doinbackground() 08-08 12:52:55.064: e/androidruntime(3484):     @ android.os.asynctask$3.done(asynctask.java:299) 08-08 12:52:55.064: e/androidruntime(3484):     @ java.util.concurrent.futuretask$sync.innersetexception(futuretask.java:273) 08-08 12:52:55.064: e/androidruntime(3484):     @ java.util.concurrent.futuretask.setexception(futuretask.java:124) 08-08 12:52:55.064: e/androidruntime(3484):     @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:307) 08-08 12:52:55.064: e/androidruntime(3484):     @ java.util.concurrent.futuretask.run(futuretask.java:137) 08-08 12:52:55.064: e/androidruntime(3484):     @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 08-08 12:52:55.064: e/androidruntime(3484):     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076) 08-08 12:52:55.064: e/androidruntime(3484):     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569) 08-08 12:52:55.064: e/androidruntime(3484):     @ java.lang.thread.run(thread.java:856) 08-08 12:52:55.064: e/androidruntime(3484): caused by: java.lang.noclassdeffounderror: org.jsoup.jsoup 08-08 12:52:55.064: e/androidruntime(3484):     @ com.wfwf.everestnewsapp.parser.domparser.parsexml(domparser.java:102) 08-08 12:52:55.064: e/androidruntime(3484):     @ com.wfwf.everestnewsapp.splash$asyncloadxmlfeed.doinbackground(splash.java:131) 08-08 12:52:55.064: e/androidruntime(3484):     @ com.wfwf.everestnewsapp.splash$asyncloadxmlfeed.doinbackground(splash.java:1) 08-08 12:52:55.064: e/androidruntime(3484):     @ android.os.asynctask$2.call(asynctask.java:287) 08-08 12:52:55.064: e/androidruntime(3484):     @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305)  08-08 12:52:55.064: e/androidruntime(3484):     ... 5 more 

try example...

    import java.net.url; import java.util.arraylist; import javax.xml.parsers.documentbuilder; import javax.xml.parsers.documentbuilderfactory;  import org.w3c.dom.document; import org.w3c.dom.element; import org.w3c.dom.node; import org.w3c.dom.nodelist; import org.xml.sax.inputsource;  import android.app.activity; import android.content.context; import android.os.bundle; import android.text.html; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.listview; import android.widget.textview;  public class xmlparsingdomexample extends activity {      arraylist<string> title;     arraylist<string> description;     arraylist<string> pubdate;      itemadapter adapter1;     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          listview list = (listview) findviewbyid(r.id.list);         title = new arraylist<string>();         description = new arraylist<string>();           pubdate = new arraylist<string>();            try {              url url = new url(                     "your url");             documentbuilderfactory dbf = documentbuilderfactory.newinstance();             documentbuilder db = dbf.newdocumentbuilder();             document doc = db.parse(new inputsource(url.openstream()));             doc.getdocumentelement().normalize();              nodelist nodelist = doc.getelementsbytagname("item");             (int = 0; < nodelist.getlength(); i++) {                  node node = nodelist.item(i);                         element fstelmnt = (element) node;                 nodelist namelist = fstelmnt.getelementsbytagname("title");                 element nameelement = (element) namelist.item(0);                 namelist = nameelement.getchildnodes();                          log.v("title--", ""+ ((node) namelist.item(0)).getnodevalue());                 title.add(""+ ((node) namelist.item(0)).getnodevalue());                  nodelist websitelist = fstelmnt.getelementsbytagname("description");                 element websiteelement = (element) websitelist.item(0);                 websitelist = websiteelement.getchildnodes();                 log.v("description--", ""+ ((node) websitelist.item(0)).getnodevalue());                             description.add(""+ ((node) websitelist.item(0)).getnodevalue());                     nodelist websitelist1 = fstelmnt.getelementsbytagname("pubdate");                 element websiteelement1 = (element) websitelist1.item(0);                 websitelist1 = websiteelement1.getchildnodes();                  pubdate.add(""+ ((node) websitelist1.item(0)).getnodevalue());                }         } catch (exception e) {             system.out.println("xml pasing excpetion = " + e);         }          adapter1 = new itemadapter(this);         list.setadapter(adapter1);     }       class itemadapter extends baseadapter {          final layoutinflater minflater;          private class viewholder {             public textview title_text;             public textview des_text;             public textview date_text;         }          public itemadapter(context context) {             // todo auto-generated constructor stub             super();             minflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service);              }          //@override         public int getcount() {             return title.size();         }          //@override         public object getitem(int position) {             return position;         }          //@override         public long getitemid(int position) {             return position;         }          //@override         public view getview(final int position, view convertview, viewgroup parent) {             view view = convertview;             final viewholder holder;             if (convertview == null) {                 view = minflater.inflate(r.layout.mainpage_listitem_activity, parent, false);                 holder = new viewholder();                 holder.title_text = (textview) view.findviewbyid(r.id.title_text);                 holder.des_text = (textview) view.findviewbyid(r.id.des_text);                 holder.date_text = (textview) view.findviewbyid(r.id.date_text);                  view.settag(holder);             } else {                 holder = (viewholder) view.gettag();             }              holder.title_text.settext(""+title.get(position));              holder.des_text.settext(""+html.fromhtml(description.get(position)));             holder.date_text.settext(""+pubdate.get(position));                   return view;         }     } } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -