android - How to getSharedPreferences in Application? -


i tried call getsharedpreferences in application...

public class app extends application{     public app() {         sharedpreferences prefs = getsharedpreferences(shared_preferences_name, context.mode_private);     } } 

...but got nullpointerexception:

java.lang.nullpointerexception: attempt invoke virtual method   'android.content.sharedpreferences   android.content.context.getsharedpreferences(java.lang.string, int)'    on null object reference 

i tried , got same exception:

context con = getapplicationcontext(); 

how can call getsharedpreferences?

override oncreate(), in app,

@override public void oncreate() {     super.oncreate(); 

and there. don't forget declare application subclass in androidmanifest well. e.g.

  <application         android:name="app" 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -