Hi,
         If u r creating sharedpreferences in our activity class means
then it wont show any error other wise if u r creating shared
preferences in other java class then it ll shows errors.
in that case u need to pass the context or activity object.

this is the sample code

public class SharedPrefEx {

        public void saveData(Context context, String value) {
                SharedPreferences prefs = 
context.getSharedPreferences("MyPrefs",
Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = prefs.edit();
                editor.putString("One", value);
                editor.commit();
        }
}

u can call this method by creating object in our activity class i.e.
SharedPrefEx  sharedPrefs = new SharedPrefs();
sharedPrefs.saveData("Seshu");


On Mar 11, 9:03 am, Deepa M <[email protected]> wrote:
> SharedPreferences myPrefs =
> youractivityname.this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
>   SharedPreferences.Editor prefsEditor = myPrefs.edit();
>
>
>
>
>
>
>
>
>
> On Sun, Mar 10, 2013 at 12:15 AM, Jonathan S <[email protected]> wrote:
> > in Shared1, Context.MODE_PRIVATE
> > in Shared2, 
> > getContext().getSharedPreferences<http://developer.android.com/reference/android/content/Context.html#g...>("top5",
> > Context.MODE_PRIVATE)
>
> > On Saturday, March 9, 2013 4:43:08 AM UTC-5, lselwd wrote:
>
> >> I have problem working with SHARED PREFERENCES, I think is project
> >> specific... i used the same before without errors but now get error.... see
> >> attachments, well?
>
> >  --
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
> > ---
> > You received this message because you are subscribed to the Google Groups
> > "Android Developers" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to [email protected].
> > For more options, visithttps://groups.google.com/groups/opt_out.
>
> --
> Thanks& Regards
> Deepa M

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to