我有一个名为AppVariable的类,它扩展了Application类
这是我的AppVariable#OnCreate()方法,以及我想要检索的对象的getter和setter:
public void onCreate() {
super.onCreate();
//set Facebook Manager
setFacebookManager(new FacebookManager(this));
}
/**
* Getter for FacebookManager Object
* @return the FacebookConnectionManager object
*/
public FacebookManager getFacebookManager() {
return this.facebookManager;
}
/**
* Setter for FacebookManager object
* @param facebookManager the new FacebookConnectionManager object
*/
public void setFacebookManager(FacebookManager facebookManager) {
this.facebookManager = facebookManager;
}
在我的Activity里面我试图从AppVariable对象中获取FacebookManager对象 - 但它总是返回null:
/**
* Authorize with facebook
*/
public void facebookAuthorization()
{
AppVaiable app = (AppVariables) getApplication();
//Connecting with Facebook
loadingStatus.setText("Connecting with Facebook");
//authorize to Facebook
app.getFacebookManager().getFacebook().authorize(this, getResources().getStringArray(R.array.facebookPermissions), new AuthorizeDialogListener(app));
}
任何想法为什么?
答案 0 :(得分:0)
你确定你的nullpointer出现在“app.getFacebookManager()”。我建议您打印所有方法结果,并查看null的来源:
Log.d("YourClass", "Manager: "+ app.getFacebookManager());
Log.d("YourClass", "FAcebook: "+ app.getFacebookManager().getFacebook());