title: Android dev - Issue with using SeekBar
body: <p>I'm trying to implement a SeekBar in a simple flashlight app (that I'm learning on) and cannot understand why the app keeps crashing when I set the OnSeekBarChangeListener to my SeekBar.  As soon as a remove all of the code inside the onStopTrackingTouch() for the listener, the app runs fine.  But if there is anything at all inside the listener's methods, it crashes.  I'm also using buttons and gestures in the app and have not had any problems using those.</p>
  
  <p>I am bringing up a separate layout when the user presses the Menu button | Brightness option, which displays the SeekBar (to adjust the brightness)</p>
  
  <p>Here is the how I am implementing the SeekBar:</p>
  
  <pre><code>SeekBar mSeekBar;
  
  ...
  
  @Override 
  public void onCreate(Bundle savedInstanceState){
  setContentView(R.layout.main);
  
  ...
  
  mSeekBar = (SeekBar)findViewById(R.id.mSeekbar);
          mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
  
          @Override
              public void onStopTrackingTouch(SeekBar seekBar) {
                  //first set the brightness mode to manual
                  Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
  
                  //change the actual setting
                  WindowManager.LayoutParams lp = getWindow().getAttributes();
                  float brightness = Float.valueOf(seekBar.getProgress()); //change the brightness here
                  lp.screenBrightness = brightness;
                  getWindow().setAttributes(lp); //set the new brightness
              }
  
              @Override
              public void onStartTrackingTouch(SeekBar seekBar) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void onProgressChanged(SeekBar seekBar, int progress,
                      boolean fromUser) {
                  // TODO Auto-generated method stub
              }
          });
  </code></pre>
  
  <p>Thank you for your time and advice.</p>
  
  <p>UPDATE:  Here is the link to my Logcat info  <a href="http://pastie.org/2561098" rel="nofollow">http://pastie.org/2561098</a>  </p>
  
  <p>UPDATE 2: Here is the link to my release run LogCat info:  <a href="http://pastie.org/2561111" rel="nofollow">http://pastie.org/2561111</a>  </p>
  
  <p>SOLVED:</p>
  
  <p>I had mSeekBar being instantiated and the listener's set before the layout was present.  The SeekBar was null because the separate layout I made for adjusting the brightness was not currently in view.  Putting the instantiation and listener's inside the switch statement I use for options menu, after the new layout (for the brightness) is set works perfectly.</p>
  
  <p>Thank you!</p>