Backendless Support
 
Solved

Internal nullpointer at login/register

Hi, I am trying to login/register with BE Android SDK, but have some problems.

When I am trying to call login or register methods async, I am getting at SDK UserService in callback methodhandleResponse(User response) response as null. And then app crashes with

  1. java.lang.NullPointerException: Attempt to invoke virtual method 'void com.backendless.BackendlessUser.setPassword(java.lang.String)' on a null object reference
  2. at com.backendless.UserService$1.handleResponse(UserService.java:108)
  3. at com.backendless.UserService$1.handleResponse(UserService.java:104)
  4. at com.backendless.async.message.AsyncMessage$ResponseHandler.handle(AsyncMessage.java:64)
  5. at com.backendless.async.message.AsyncMessage.handleCallback(AsyncMessage.java:41)
  6. at com.backendless.core.AndroidCarrier$1.handleMessage(AndroidCarrier.java:37)
  7. at android.os.Handler.dispatchMessage(Handler.java:107)
  8. at android.os.Looper.loop(Looper.java:207)
  9. at android.app.ActivityThread.main(ActivityThread.java:5977)
  10. at java.lang.reflect.Method.invoke(Native Method)
  11. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:940)
  12. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:801)

User creation:

  1. BackendlessUser backendlessUser = new BackendlessUser();

    backendlessUser.setEmail(email);

    backendlessUser.setPassword(password);

    backendlessUser.setProperty("name", name);

Permission for INTERNET exists.

SDK initialization:

  1. Backendless.initApp(this, APPLICATION_ID, API_KEY);
  2. Backendless.setUrl(SERVER_URL);

Keys doublechecked, registration enabled at console, have no idea what is the problem.Will appreciate any help.

Best,Nick.

Best Answer
photo

Finally, problem was in DASH("-") in keys, I don't know how, but they wasn't there after I copied keys. I am so sorry for disturbing you. Have a great day!

Leave a Comment

Comments (10)

photo
1

Hi Nick,

The code you shared for user creation does not seem to be able to cause the exception (by looking at the stack trace). Have you tried running the program in a debugger to see where exactly the exception occurs?

Regards,

Mark

photo
1

Hi Mark, yes, crash happens in method handleResponse in SDK class UserService, because response comes there as a null. So it does not go to fault method, it goes with success, but with null response. I also should say that I am wrapping this call in rxJava, but don't think that problem is in it.

photo
photo
1

Hi Mark, yes, crash happens in method handleResponse in SDK class UserService, because response comes there as a null. So it does not go to fault method, it goes with success, but with null response. I also should say that I am wrapping this call in rxJava, but don't think that problem is in it.

photo
1

Hi Nick,

Is there a possibility of two concurrent remote calls to the server going on when it happens?

Regards,

Mark

photo
1

Hey, I don't think so, I am just calling smth like this:

  1. return Single.create(e -> Backendless.UserService.register(backendlessUser, new BackendlessCallback<BackendlessUser>() {
  2. @Override
  3. public void handleResponse(BackendlessUser user) {
  4. e.onSuccess(true);
  5. }
  6. @Override
  7. public void handleFault(BackendlessFault backendlessFault) {
  8. e.onSuccess(false);
  9. }
  10. }));

photo
1

Thanks, we will give it a try and hopefully be able to reproduce.

What version of rxJava do you use? Also, are you on the latest build of the Backendless SDK?

photo
1

I am using 4.0.2 for Backendless SDK and RxJava 2.0.8. Thanks!

photo
1

I tried without any RxJava, just with async callback, and still nullpointer in internal UserService class, because onResponse null. I am pretty sure problem is that I init smth wrong or smth like that, but I have no idea what.

photo
1

Finally, problem was in DASH("-") in keys, I don't know how, but they wasn't there after I copied keys. I am so sorry for disturbing you. Have a great day!

photo
photo
1

Hello,

here it is my example

  1. Backendless.initApp(this, "app-id, "api-key");

    final BackendlessUser backendlessUser = new BackendlessUser();

    backendlessUser.setEmail( "s@k0" );

    backendlessUser.setPassword("dddd");

    Single.create(new SingleOnSubscribe<Object>() {

    @Override

    public void subscribe(final SingleEmitter<Object> e) throws Exception {

    Backendless.UserService.register(backendlessUser, new BackendlessCallback<BackendlessUser>() {

    @Override

    public void handleResponse(BackendlessUser user) {

    e.onSuccess(true);

    Log.i("user", user.getObjectId());

    }

    @Override

    public void handleFault(BackendlessFault backendlessFault) {

    e.onSuccess(false);

    Log.e("user_fault", backendlessFault.getMessage());

    }

    });

    }

    }).subscribe();

and result

  1. 08-10 18:49:26.575 4571-4571/com.example.ksv.myapplication I/user: 6DC6C984-DB40-6FA9-FFE1-2DDB52579200

so it works