Skip to content

Attempt to invoke virtual method 'int .......getId()' on a null object reference #2

@gkokam

Description

@gkokam

Hello Team
Thanks very much for helping.

Plz after following the tutorial #16 Retrofit Android Tutorial - Profile Activity

i m getting this issue in my code

Attempt to invoke virtual method 'int .......getId()' on a null object reference
at public void saveUser(User user) {

    SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();

    editor.putInt("id", user.getId());
    editor.putString("email", user.getEmail());
    editor.putString("name", user.getName());
    editor.putString("school", user.getSchool());

    editor.apply();

Can you help to find what is the issue and fix it ??

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions