probelalkhan / Retrofit-Android-Tutorial

48 stars 61 forks source link

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

Open gkokam opened 4 years ago

gkokam commented 4 years ago

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