Making android game: can not acces my SharedPreferences in class which extends SurfaceView implements SurfaceHolder.Callback
<p>I am making an android java game. But I am a little bit stuck on getting my saved gender string.</p>

<p>In my GameGameActivity class I can receive the gender. </p>

<pre><code>public class GameGameActivity extends GameActivity{

SharedPreferences mGameSettings;
public String mGender;
MainGamePanel mGamePanel;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.game);
    mGameSettings = getSharedPreferences(GAME_PREFERENCES, Context.MODE_PRIVATE);
    Log.d("myTag", "View added");
   checkGender();
}

private void checkGender(){
    if (mGameSettings.contains(GAME_PREFERENCES_GENDER)) {
        if(mGameSettings.getInt(GAME_PREFERENCES_GENDER, 0) == 2){
            mGender = "Female";             
            Log.d("myTag","gender: " +mGender );
        }else{
            mGender = "Male";
            Log.d("myTag","gender: " +mGender );
        }
    }
}
</code></pre>

<p>But all the magic happens in my MainGamePanel. I want know what gender it is in there. I tried in many ways but it always give me a nullpointer exception. This is my MainGamePanel. (only a few lines)</p>

<pre><code>public class MainGamePanel extends SurfaceView implements SurfaceHolder.Callback{
public MainGamePanel(Context context, AttributeSet attributeSet){
    super(context, attributeSet);
    background =       BitmapFactory.decodeResource(getResources(),R.drawable.bg_game_boy);
    getHolder().addCallback(this);  
    createContent();
    thread = new MainThread(getHolder(), this);
    setFocusable(true); 
}
</code></pre>

<p>This is the class where i saved the gender ect. I can get acces to them in other Activity's but they all extentends this class:</p>

<pre><code>import android.app.Activity;
public class GameActivity extends Activity{

public static final String GAME_PREFERENCES = "GamePrefs";
public static final String GAME_PREFERENCES_NICKNAME = "Nickname"; // String
public static final String GAME_PREFERENCES_EMAIL = "Email"; // String
public static final String GAME_PREFERENCES_PASSWORD = "Password"; // String
public static final String GAME_PREFERENCES_DOB = "DOB"; // Long
public static final String GAME_PREFERENCES_GENDER = "Gender"; //

public static final String GAME_PREFERENCES_SCORE = "80"; // int

public static final String DEBUG_TAG = "Activity Log";
public static final String TAG = GameActivity.class.getSimpleName();
</code></pre>

<p>}</p>

<p>I dont know how to read the gender preferences in my maingamepanel. Can someone tell me or push me into the right direction?</p>

<p>Thank you</p>

<p>I tried it this way after the command:
and it said: The method getSharedPreferences(String, int) is undefined for the type MainGamePanel</p>

<pre><code>    SharedPreferences mGameSettings;

public MainGamePanel(Context context, AttributeSet attributeSet){
    super(context, attributeSet);
    background = BitmapFactory.decodeResource(getResources(),R.drawable.bg_game_boy);
    getHolder().addCallback(this);  
    createContent();
    thread = new MainThread(getHolder(), this);
    setFocusable(true);     
    mGameSettings = getSharedPreferences(mGameActivity.GAME_PREFERENCES, Context.MODE_PRIVATE);
}
</code></pre>
