Support Topics Documentation Slack YouTube Blog

BackendlessUser.getEmail() returning null


(Katleho Makumane) #1

im getting a nullpointer exception when i try to get and set the the admin email to a textView even though the code works when i do the same for the coach.
APP_ID E77A750E-90AF-5F30-FFC9-FB6D85033E00

BackendlessUser user = Backendless.UserService.CurrentUser();

role = (String)user.getProperty(“role”);

if(role != null)
{
if(role.equals(“None”))
{
}
else if (role.equals(“Coach”))
{
tvCoachRole.setText(user.getProperty(“role”).toString());
tvCoachEmail.setText(user.getEmail());

       }
        else
        {
            tvAdminRole.setText(user.getProperty("role").toString());
            tvAdminEmail.setText(user.getEmail());
        }

`}


(Anton Govorushkin) #2

Hi Katleho

I’ve just recreated the same schema as you have in your ‘Users’ table of your app and tried your code in plain Java app. Logic works fine, when i’m logging in a “Coach” and “Admin”. The only Backendless API that I see in your snippet is getting currently logged in user, which works as expected.
Debug your code in order to find out at what line your NPE occurs and what’s the reason for it. CurrentUser() API is not user-dependent and works exactly the same for any logged in user within Users table

Anton


(Katleho Makumane) #3

Turns out it i had deleted the line connecting to the textview, the i couldnt find it sooner is because i was relying on the debugger, thanks though.