how to update SharedPreference from other activity?
<p>I have created SharedPreference in my LogIn class and i put in in a method SavedPreference()</p>

<h2>LogIn.java</h2>

<pre><code>public void SavePreferences(String key, String value){
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    SharedPreferences.Editor editor = sharedPreferences.edit();

    editor.putString(key, value);
    editor.commit();

}
</code></pre>

<p>now in my other activity, i want to update it or put string to it by calling the method and adding these paramaters after clicking the ok button.</p>

<h2>Menu.java</h2>

<pre><code>ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String oldpassword = oldpass.getText().toString();
                    String newpassword = newpass.getText().toString();
                    if (LogIn.s.toString().equals("1234")) {
                        if (oldpassword.toString().equals("1234")) {
                            logIn.SavePreferences("password",newpassword);
                            Toast.makeText(Menu.this,"New password saved!",Toast.LENGTH_SHORT).show();
                        }
                        else {
                            Toast.makeText(Menu.this,"Old Password is not correct",Toast.LENGTH_SHORT).show();
                        }
                    }
                    else {
                        if (oldpassword.equals(LogIn.realpass)){
                            logIn.SavePreferences("password",newpassword);
                            Toast.makeText(Menu.this,"New password saved!",Toast.LENGTH_SHORT).show();
                        }
                        else{
                            Toast.makeText(Menu.this,"Old Password is not correct",Toast.LENGTH_SHORT).show();
                        }
                    }

                }
            });
</code></pre>

<p>But after clicking ok, my app crashes and LogCat shows this</p>

<pre><code>02-06 13:21:55.834 6327-6327/com.secsys.gagacamaso.gagacamaso E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: com.secsys.gagacamaso.gagacamaso, PID: 6327
                                                                            java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
                                                                                at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:107)
                                                                                at com.secsys.gagacamaso.gagacamaso.LogIn.SavePreferences(LogIn.java:191)
                                                                                at com.secsys.gagacamaso.gagacamaso.Menu$3$1.onClick(Menu.java:133)
                                                                                at android.view.View.performClick(View.java:5198)
                                                                                at android.view.View$PerformClick.run(View.java:21147)
                                                                                at android.os.Handler.handleCallback(Handler.java:739)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                at android.os.Looper.loop(Looper.java:148)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
</code></pre>

<p>LogIn.java:191 is this <code>SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());</code></p>

<p>and Menu.java:133 is this <code>logIn.SavePreferences("password",newpassword);</code></p>