java - Null pointer exception in Simple Facebook library to getPosts? -


i imported this library posts set imports , so, have follow steps , wirte code,actually wanted show page's public posts in app.like apps or website keeps looks facebook's real page. possible or not in android? thanks.

package algonation.com.myapplication;  import android.graphics.paint; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.text.html; import android.util.log; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.textview;  import com.sromku.simple.fb.simplefacebook; import com.sromku.simple.fb.actions.cursor; import com.sromku.simple.fb.entities.post; import com.sromku.simple.fb.listeners.onpostslistener;  import java.util.list;   public class facebookactivity extends actionbaractivity { private final static string example = ""; private string mallpages = ""; onpostslistener onpostslistener = new onpostslistener() {     @override     public void oncomplete(list<post> posts) {         log.i(example, "number of posts = " + posts.size());     }  /*  * can override other methods here:  * onthinking(), onfail(string reason), onexception(throwable throwable)  */ };  private textview mresult; private button mgetbutton; private textview mmore;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_facebook);     mresult = (textview) findviewbyid(r.id.result);     mmore = (textview) findviewbyid(r.id.load_more);     mmore.setpaintflags(mmore.getpaint().getflags() | paint.underline_text_flag);     mgetbutton = (button) findviewbyid(r.id.button);     mgetbutton.settext(example);     mgetbutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             mallpages = "";             mresult.settext(mallpages);             simplefacebook.getinstance().getposts(new onpostslistener() {                 @override                 public void onthinking() {                 }                  @override                 public void onexception(throwable throwable) {                     mresult.settext(throwable.getmessage());                 }                  @override                 public void onfail(string reason) {                     mresult.settext(reason);                 }                  @override                 public void oncomplete(list<post> response) {                     // make result more readable.                     mallpages += "<u>\u25b7\u25b7\u25b7 (paging) #" + getpagenum() + " \u25c1\u25c1\u25c1</u><br>";                     mallpages += com.sromku.simple.fb.utils.utils.join(response.iterator(), "<br>", new com.sromku.simple.fb.utils.utils.process<post>() {                         @override                         public string process(post post) {                             return "\u25cf " + post.getmessage() == null || "null".equalsignorecase(post.getmessage()) ? post.getid() : post.getmessage() + " \u25cf";                         }                     });                     mallpages += "<br>";                     mresult.settext(html.fromhtml(mallpages));                     // check if more pages exist                     if (hasnext()) {                         enableloadmore(getcursor());                     } else {                         disableloadmore();                     }                 }             });         }     });  }   @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_facebook, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();      //noinspection simplifiableifstatement     if (id == r.id.action_settings) {         return true;     }      return super.onoptionsitemselected(item); }  private void enableloadmore(final cursor<list<post>> cursor) {     mmore.setvisibility(view.visible);     mmore.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view arg0) {             mallpages += "<br>";             cursor.next();         }     }); }  private void disableloadmore() {     mmore.setonclicklistener(null);     mmore.setvisibility(view.invisible); } } 

if @ code of library, you'll see note:

/**  * instance of {@link com.sromku.simple.fb.simplefacebook}. <br>  * <br>  * <b>important:</b> use method after initialized library  * or by: {@link #initialize(android.app.activity)} or {@link #getinstance(android.app.activity)}  *  * @return {@link com.sromku.simple.fb.simplefacebook} instance  */ 

you should use simplefacebook.getinstance(facebookactivity.this) because method you're using return uninitialised reference (null), unless have initialised previously.

please spend time reading documentation of library - guy has spent time working on huge wiki.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -