Support Topics Documentation Slack YouTube Blog

Internal nullpointer at login/register


(Nike Teo) #1

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


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

User creation:

BackendlessUser backendlessUser = new BackendlessUser();
backendlessUser.setEmail(email);
backendlessUser.setPassword(password);
backendlessUser.setProperty("name", name);

Permission for INTERNET exists.
SDK initialization:

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

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


(Mark Piller) #2

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


(Nike Teo) #3

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.


(Nike Teo) #4

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.


(Mark Piller) #5

Hi Nick,

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

Regards,
Mark


(Nike Teo) #6

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

return Single.create(e -> Backendless.UserService.register(backendlessUser, new BackendlessCallback<BackendlessUser>() {
      @Override
      public void handleResponse(BackendlessUser user) {
        e.onSuccess(true);
      }


      @Override
      public void handleFault(BackendlessFault backendlessFault) {
        e.onSuccess(false);
      }
    }));

(Mark Piller) #7

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?


(Nike Teo) #8

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


(Sergey Kukurudzyak) #9

Hello,

here it is my example

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

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

so it works


(Nike Teo) #10

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.


(Nike Teo) #11

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!