Bmob报错:cn.bmob.v3.BmobWrapper.getApplicationContext()' on a null object reference

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context

cn.bmob.v3.BmobWrapper.getApplicationContext()' on a null object reference

at cn.bmob.v3.Bmob.Code(Bmob.java:130)
at cn.bmob.v3.Bmob.getApplicationContext(Bmob.java:143)
at cn.bmob.v3.http.thing.I(BmobFactory.java:71)
at cn.bmob.v3.http.thing.Code(BmobFactory.java:157)
at cn.bmob.v3.BmobUser.signUp(BmobUser.java:204)

at com.joey.slave.RegisterActivity.onRegisterClick(RegisterActivity.java:61)


问题:使用Bmob作为Android后台数据支持,在进行注册功能编写时,报出以上错误.

原因是没有在相应的activity将Bmob初始化, demo实际情况如下:

在LoginActivity中通过Bmob验证账号密码, 需要先初始化Bmob

在RegisterActivity使用Bmob进行账号注册, 也要先进行初始化

解决方式:
// 初始化Bmob功能
Bmob.initialize(this, Constants.Bmob_APPID); // Constants.Bmob_APPID: Bmob的APPID

你可能感兴趣的:(Android)