title: Why is my integer always zero?
body: <p>I am embarrassed to have such a simple question, but I just don't know what I'm doing wrong. I'm trying to have a level unlock after score 20. The first time the level gets unlocked, I want to give the user a message saying "level unlocked". I do this like so:</p>
  
  <pre><code>if(firstTimeOne == 0 &amp;&amp; currentHighOne.getInt("levelOneHigh", 0) &gt;= 20){ //First time getting a score over 20
                  Toast.makeText(LevelSelect.this, "Unlocked level two!" +firstTimeOne, Toast.LENGTH_SHORT).show();
                  firstTimeOne=1;
              }
  </code></pre>
  
  <p>The problem is, this code executes <strong>every</strong> time the user gets a score over 20... The firstTimeOne variable should be preventing that, right? It is set to <code>1</code> after this method has been called, preventing it to be called again. So, why is this method getting called more than once?</p>
  
  <p>I make the variable <code>firstTimeOne</code> in my class, where I write:</p>
  
  <pre><code>int firstTimeOne = 0;
  </code></pre>
  
  <p>If you need my full code, here it is. It shows that I initialize the int in the class, rather than in a method:</p>
  
  <p><a href="https://gist.github.com/anonymous/b52a5873b9eb9324e671" rel="nofollow">https://gist.github.com/anonymous/b52a5873b9eb9324e671</a></p>
  
  <p>EDIT:</p>
  
  <p>Okay, so I am trying SharedPreferences, but get a null pointer exception on `edit.putInt("firstInt", 1); Here is the code: <a href="https://gist.github.com/anonymous/c5b71982559c245220df" rel="nofollow">https://gist.github.com/anonymous/c5b71982559c245220df</a></p>
  
  <hr>
  
  <pre><code>   //ints will be zero if they do not have a value assigned to them...right?
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_level_select);
  
          levelTwoButton = (Button) findViewById(R.id.leveltwo);
  
          SharedPreferences currentHighOne = this.getSharedPreferences("levelOneScore", Context.MODE_PRIVATE);
          if (currentHighOne.getInt("levelOneHigh", 0) &lt; 20) {
              levelTwoButton.setClickable(false);
              levelTwoButton.setText("Level two is locked!");
          }else{
  
              SharedPreferences firstTimeOne = this.getSharedPreferences("firstTimeOne", Context.MODE_PRIVATE); //Making a shared pref
  
              if(firstTimeOne.getInt("firstInt" , 5) == 5) { //Check if I've stored values in it yet
                  edit = firstTimeOne.edit();
                  edit.putInt("firstInt", 0); //Setting the default as 0
                  edit.commit();
              }
              if(firstTimeOne.getInt("firstInt", 0) == 0 &amp;&amp; currentHighOne.getInt("levelOneHigh", 0) &gt;= 20){ //First time getting a score over 20
                  Toast.makeText(LevelSelect.this, "Unlocked level two!" +firstTimeOne, Toast.LENGTH_SHORT).show();
  
                  edit.putInt("firstInt", 1);
              }
          }
      }
  </code></pre>
  
  <p>Thanks so much for everything,</p>