Android Rss feed from facebook page -
Android Rss feed from facebook page -
the info received , shown on log. can't seem display on screen. keeps saying java.lang.string cannot converted jsonobject. tried these lines in project , seems working fine.
here code many in advance:
mainactivity.java
package synctc.me.rssfeed; import android.nfc.tag; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.util.log; import android.view.menu; import android.view.menuitem; import android.widget.textview; import android.widget.toast; import com.squareup.okhttp.call; import com.squareup.okhttp.callback; import com.squareup.okhttp.okhttpclient; import com.squareup.okhttp.request; import com.squareup.okhttp.response; import org.json.jsonexception; import org.json.jsonobject; import java.io.ioexception; import butterknife.butterknife; import butterknife.injectview; public class mainactivity extends actionbaractivity { public static final string tag = mainactivity.class.getsimplename(); private current mcurrent ; @injectview(r.id.title)textview mtitle; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); butterknife.inject(this); geturl(); log.d(tag,"main ui running"); } private void geturl(){ string url ="https://www.facebook.com/feeds/page.php?format=rss20&id=311612925545909"; okhttpclient client = new okhttpclient(); request request = new request.builder() .url(url) .build(); phone call call=client.newcall(request); call.enqueue(new callback() { @override public void onfailure(request request, ioexception e) { runonuithread(new runnable() { @override public void run() { } }); } @override public void onresponse(response response) throws ioexception { runonuithread(new runnable() { @override public void run() { } }); seek { string jsondata = response.body().string(); log.v(tag, jsondata); if(response.issuccessful()){ mcurrent = getcurrentdetails(jsondata); runonuithread(new runnable() { @override public void run() { updatedisplay(); } }); }else{ } } grab (ioexception e) { log.e(tag, "exception caught : ",e); } grab (jsonexception e){ log.e(tag, "exception caught : ",e); } } });} private void updatedisplay (){ mtitle.settext(mcurrent.gettitle()+""); } private current getcurrentdetails(string jsondata) throws jsonexception{ jsonobject channel = new jsonobject (jsondata); string channelval = channel.getstring("channel"); jsonobject = new jsonobject(channel.get("channel").tostring()); current current = new current(); current.settitle(currently.getstring("title")); log.i(tag,"from json to:"+channelval); homecoming current; } }
current.java
public class current { private string mchannel; private string mtitle; private string mdescription; private string mimg; public string getdescription() { homecoming mdescription; } public void setdescription(string description) { mdescription = description; } public string getimg() { homecoming mimg; } public void setimg(string img) { mimg = img; } public string gettitle() { homecoming mtitle; } public void settitle(string title) { mtitle = title; } public string getchannel() { homecoming mchannel; } public void setchannel(string channel) { mchannel = channel; } }
here logcat
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:dc="http://purl.org/dc/elements/1.1/" > <channel> <title>حائط professional hackers على فيسبوك</title> <link>https://www.facebook.com/</link> <description>حائط professional hackers على فيسبوك</description> <language>en-us</language> <category domain="facebook">pagesyndicationfeed</category> <generator>facebook syndication</generator><docs>http://www.rssboard.org/rss-specification</docs> <lastbuilddate>mon, 08 sep 2014 10:48:32 +0000</lastbuilddate> <webmaster>webmaster@facebook.com</webmaster> <item> <guid ispermalink="false">www.facebook.com/notification/847a02dda3e67da1443312712cc478b4</guid> <title><![cdata[ ]]></title> <link>http://www.facebook.com/professionalhackers00/photos/a.342883082418893.81113.311612925545909/825529307487599/?type=1</link> <description><![cdata[<a href="/professionalhackers00/photos/a.342883082418893.81113.311612925545909/825529307487599/?type=1&relevant_count=1" id="" title="" target="" onclick="" style=""><img class="img" src="https://m.ak.fbcdn.net/sphotos-g.ak/hphotos-ak-xta1/v/t1.0-9/s130x130/10665141_825529307487599_4548128653985487900_n.png?oh=6469cb21ce0091796b296364f61232fa&oe=55ab5930&__gda__=1436725829_d9cda3c297f41ce6485f644c528b429e" alt="" /></a><br/>]]></description> <pubdate>mon, 08 sep 2014 11:48:32 +0100</pubdate> <author>professional hackers</author> <dc:creator>professional hackers</dc:creator> </item> <item> <guid ispermalink="false">www.facebook.com/notification/d22710b9bde130cf6d5efda7d4256f7e</guid> <title><![cdata[ tired of blocked websites? !! trick certainly help top methods to...]]></title> <link>http://www.facebook.com/professionalhackers00/posts/825529050820958</link> <description><![cdata[tired of blocked websites? !! trick certainly help <br /> <br /> top methods open / access blocked sites without proxy <br /> <br /> visit: <a href="http://l.facebook.com/l.php?u=http%3a%2f%2fgoo.gl%2fvl0hb9&h=gaqgflvzp&s=1" rel="nofollow nofollow" target="_blank" onmouseover="linkshimasynclink.swap(this, "http:\/\/goo.gl\/vl0hb9");" onclick="linkshimasynclink.swap(this, "http:\/\/l.facebook.com\/l.php?u=http\u00253a\u00252f\u00252fgoo.gl\u00252fvl0hb9&h=gaqgflvzp&s=1");">http://goo.gl/vl0hb9</a><br /> <br/><br/><a href="http://l.facebook.com/l.php?u=http%3a%2f%2fgoo.gl%2fvl0hb9&h=caqg3txib&s=1" id="" title="" target="" onclick="linkshimasynclink.swap(this, "http:\/\/l.facebook.com\/l.php?u=http\u00253a\u00252f\u00252fgoo.gl\u00252fvl0hb9&h=caqg3txib&s=1");" style="" rel="nofollow" onmouseover="linkshimasynclink.swap(this, "http:\/\/goo.gl\/vl0hb9");"><img class="img" src="https://m.ak.fbcdn.net/external.ak/safe_image.php?d=aqcqiahuknlbcfwh&w=158&h=158&url=https%3a%2f%2fscontent-a-vie.xx.fbcdn.net%2fhphotos-xpf1%2fv%2ft1.0-9%2f10603264_825528994154297_1736307390360087029_n.png%3foh%3dc48a5971b5dfc19555267662e13c219a%26oe%3d54949e9d" alt="" /></a><br/><a href="http://l.facebook.com/l.php?u=http%3a%2f%2fgoo.gl%2fvl0hb9&h=waqfr5mbg&s=1" id="" target="_blank" onclick="linkshimasynclink.swap(this, "http:\/\/l.facebook.com\/l.php?u=http\u00253a\u00252f\u00252fgoo.gl\u00252fvl0hb9&h=waqfr5mbg&s=1");" style="" rel="nofollow" onmouseover="linkshimasynclink.swap(this, "http:\/\/goo.gl\/vl0hb9");">top methods open / access blocked sites without proxy | cool tips , tricks</a><br/>www.gotipsandtrick.info]]></description> <pubdate>mon, 08 sep 2014 11:47:17 +0100</pubdate> <author>professional hackers</author> <dc:creator>professional hackers</dc:creator> </item> <item> <guid ispermalink="false">www.facebook.com/notification/d5aa50993c46015a9af 04-08 07:29:00.338 1875-1893/synctc.me.rssfeed e/mainactivity﹕ exception caught : org.json.jsonexception: value <?xml of type java.lang.string cannot converted jsonobject @ org.json.json.typemismatch(json.java:111) @ org.json.jsonobject.<init>(jsonobject.java:160) @ org.json.jsonobject.<init>(jsonobject.java:173) @ synctc.me.rssfeed.mainactivity.getcurrentdetails(mainactivity.java:105) @ synctc.me.rssfeed.mainactivity.access$100(mainactivity.java:27) @ synctc.me.rssfeed.mainactivity$1.onresponse(mainactivity.java:73) @ com.squareup.okhttp.call$asynccall.execute(call.java:162) @ com.squareup.okhttp.internal.namedrunnable.run(namedrunnable.java:33) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:818)
the response accessing facebook link in xml format.
when parser tries read document, tries converting
?xml
into json
android rss
Comments
Post a Comment