[android-developers] Re: creating shared preferences throws null pointer exception

2012-11-26 Thread Jonathan S


*context is Context and **getApplicationContext() is Application's Context. 

There is no needed for call both context, just one context.*



On Monday, November 26, 2012 3:26:36 AM UTC-5, SIVAKUMAR.J wrote:
>
>
> Dear All,
>
>   I had android doubt.
> getSharedPreferences(sharedprefname, Context.MODE_PRIVATE) in a broad cast 
> receiver returns null pointer 
> exception?
>  
> *I'm developing an android application.Im using Android SDK 2.2*
> I'm using 2 Broadcast receivers.Receiver A start a service S1
> Receiver B starts a service S2.
> Both the recievers invoked at a time interval of 1 hour
> Receiver A is invoked @ a time 9.00,10.00 ,etc
> Receiver B is invoked @ a time 8.50,9.50 ,etc
> In a service s1 im storing some data in shared preferences
> Im storing some data in shared preferences in the receiver B.
> Im using the below code in the BroadCastReceiver for getting shared 
> preference.But it throws null pointer exeption 
>
> The coding snippet given belo
>
> *context.getApplicationContext().getSharedPreferences("myPrefs_capture_gps_per_hour",
>  Context.MODE_PRIVATE);
>
>
> *in the above code *context* is the object of the class BusinessModel.This 
> BusinessModel class is the child class of the 
> *Application(android.app.Application)*
>
>
>
>   Give ur ideas
>
>
>
> -- 
> *Thanks & Regards,
> Sivakumar.J*
>
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: creating shared preferences throws null pointer exception

2012-11-26 Thread bob
I bet either *context* is null or getApplicationContext returns null.


On Monday, November 26, 2012 2:26:36 AM UTC-6, SIVAKUMAR.J wrote:
>
>
> Dear All,
>
>   I had android doubt.
> getSharedPreferences(sharedprefname, Context.MODE_PRIVATE) in a broad cast 
> receiver returns null pointer 
> exception?
>  
> *I'm developing an android application.Im using Android SDK 2.2*
> I'm using 2 Broadcast receivers.Receiver A start a service S1
> Receiver B starts a service S2.
> Both the recievers invoked at a time interval of 1 hour
> Receiver A is invoked @ a time 9.00,10.00 ,etc
> Receiver B is invoked @ a time 8.50,9.50 ,etc
> In a service s1 im storing some data in shared preferences
> Im storing some data in shared preferences in the receiver B.
> Im using the below code in the BroadCastReceiver for getting shared 
> preference.But it throws null pointer exeption 
>
> The coding snippet given belo
>
> *context.getApplicationContext().getSharedPreferences("myPrefs_capture_gps_per_hour",
>  Context.MODE_PRIVATE);
>
>
> *in the above code *context* is the object of the class BusinessModel.This 
> BusinessModel class is the child class of the 
> *Application(android.app.Application)*
>
>
>
>   Give ur ideas
>
>
>
> -- 
> *Thanks & Regards,
> Sivakumar.J*
>
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: creating shared preferences throws null pointer exception

2012-11-26 Thread lbendlin
Why do you not use the default shared preferences? 

PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());

On Monday, November 26, 2012 3:26:36 AM UTC-5, SIVAKUMAR.J wrote:
>
>
> Dear All,
>
>   I had android doubt.
> getSharedPreferences(sharedprefname, Context.MODE_PRIVATE) in a broad cast 
> receiver returns null pointer 
> exception?
>  
> *I'm developing an android application.Im using Android SDK 2.2*
> I'm using 2 Broadcast receivers.Receiver A start a service S1
> Receiver B starts a service S2.
> Both the recievers invoked at a time interval of 1 hour
> Receiver A is invoked @ a time 9.00,10.00 ,etc
> Receiver B is invoked @ a time 8.50,9.50 ,etc
> In a service s1 im storing some data in shared preferences
> Im storing some data in shared preferences in the receiver B.
> Im using the below code in the BroadCastReceiver for getting shared 
> preference.But it throws null pointer exeption 
>
> The coding snippet given belo
>
> *context.getApplicationContext().getSharedPreferences("myPrefs_capture_gps_per_hour",
>  Context.MODE_PRIVATE);
>
>
> *in the above code *context* is the object of the class BusinessModel.This 
> BusinessModel class is the child class of the 
> *Application(android.app.Application)*
>
>
>
>   Give ur ideas
>
>
>
> -- 
> *Thanks & Regards,
> Sivakumar.J*
>
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en