-2

Getting a - cannot resolve symbol "putString" "putInt" "commit" - in the code below.Help please.

      public class Alpha extends Activity {

      public static final String GAME_PREFERENCES = "GamePrefs";
      SharedPreferences settings =getSharedPreferences(GAME_PREFERENCES,MODE_PRIVATE);

      SharedPreferences.Editor prefEditor = settings.edit();
      prefEditor.putString("Gama x","Blue Spec");
      prefEditor.putInt("Wave",292);
      prefEditor.commit();


 }
J C
  • 43
  • 7

1 Answers1

1

Before start coding randomly, have a look at some android tutorials for example this is the best in my opinion.

After you can start with coding.

btw the solution is moving it inside the "onCreate" method:

public class Alpha extends Activity {
  public static final String GAME_PREFERENCES = "GamePrefs";
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      SharedPreferences settings =getSharedPreferences(GAME_PREFERENCES,MODE_PRIVATE);

      SharedPreferences.Editor prefEditor = settings.edit();
      prefEditor.putString("Gama x","Blue Spec");
      prefEditor.putInt("Wave",292);
      prefEditor.commit();
  }
}
Pier Giorgio Misley
  • 5,305
  • 4
  • 27
  • 66