Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Data Persistence Key-Value Saving with SharedPreferences Storing a Value in SharedPreferences

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

We have an amazing app that knows the Answer to the Ultimate Question of Life, the Universe, and Everything. We need to

Can someone please help me here? I need help.. Thanks!

CodeChallenge.java
SharedPreferences mSharedPreferences;

SharedPreferences.Editor editor;

SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

2 Answers

Hello,

In your line

SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

You are trying to declare a SharedPreferences object named mSharedPreferences when you already have it declared in your first line of the Challenge. So if you just say

mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

instead, everything should be fine.

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Thanks a lot James, it helped a lot!

You're welcome. Have fun with Android Programming.