The app context object is not available in the constructor. Try moving
that code in the onbind or onStart callback methods.

Balwinder Kaur
Mobile.Software.Development
·T· · ·Mobile· stick together

The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.


On Sep 23, 7:49 pm, brooke <brooke.ma...@gmail.com> wrote:
> I have some shared preferences (user_id, email) that I want to access
> from services and classes that are not subclassed from Activity.  I
> have been trying to implement this today and keep hitting roadblocks.
>
> In particular, when I try to access getSharedPreferences, I get a null
> pointer exception. My code snippet is posted below.
>
> My goal here is to allow read access the shared preferences to objects
> and (potentially) services that aren't going to be directly exposed to
> the user.  Any suggestions/examples that can help me along?
>
> Many thanks,
>
> Brooke
>
> <snip>
> public class MyPrefs extends Service {
>     public static final String PREFS_NAME = "MyPrefs";
>     private int user_id;
>     private String user_email;
>     private String user_password;
>     private Editor editor = null;
>
>     private SharedPreferences settings = null;
>
>     public MyPrefs () {
>
>         settings = this.getSharedPreferences(PREFS_NAME,
> Context.MODE_PRIVATE);
>     }
>
> </snip>
>
> the this.getSharedPreferences line causes a null pointer exception.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to