NullPointerException AFTER logging in

Hi there
Was working on my app and tried to login via backendless as an account - something that worked perfectly so far.
but now (without even touching this class), it is causing me a NullPointerException and crashes my app.
wired thing is - the debugger sends me inside the handleResponse method:

my code:
` findViewById(R.id.btnLogin).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String uName = ((EditText)findViewById(R.id.txtUser)).getText().toString();
String uPass = ((EditText)findViewById(R.id.txtPass)).getText().toString();

            Backendless.UserService.login(uName, uPass, new AsyncCallback<BackendlessUser>() {
                @Override
                public void handleResponse(BackendlessUser response) {

        ? true : false;
                   if ((boolean) response.getProperty("isAdmin")) {
                        startActivity(new Intent(context, AdminActivity.class));
                        Log.e("admin activity","went to admin");
                    } else {
                        Intent intent = new Intent(context, ClientActivity.class);
                        intent.putExtra("name", response.getProperty("name").toString());
                        startActivity(intent);
                        Log.e("client activity","went to client");
                    }
                }

`

what im getting:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
    at com.hackeru.mybackendless.MainActivity$1$1.handleResponse(MainActivity.java:97)
    at com.hackeru.mybackendless.MainActivity$1$1.handleResponse(MainActivity.java:91)

when line 97 is -
if ((boolean) response.getProperty(“isAdmin”)) {

any help?

well i am also new to this platform but i guess you should try

if (response.getProperty("isAdmin")){
//code
}else {
//code
}

if statement will check if the condition is true or not if true then if block will execute and if not then else will

Hi @Yuval_Rafitkes

Check the properties: response.getProperties() or response.containsKey(“isAdmin”), it may be empty or does not contain the key “isAdmin” (BackendlessUser properties is HashMap).

Hi.
thank you all for you help. it happen to be an api key typo (may have clicked by mistake on refresh at some point and the one in the db didn’t match the one in the app). truly appreciate the effort, everything works perfectly now.

Have a great day!

1 Like