title: spinner drop down implementation called from fragment to a new intent
body: <p>I have an app and I made an intent that is launched from a fragment.</p>
  
  <p>However, my activity (which is an intent) runs into an error when i click the button in the fragment to start the customer player I have made.</p>
  
  <p>the error is on this line:</p>
  
  <pre><code>dropdown.setAdapter(adapter);
  </code></pre>
  
  <p>and this is the error:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Spinner.setAdapter(android.widget.SpinnerAdapter)' on a null object reference
              at blackstone.software.sunnahboxtvmenu.DuaatRadio.onCreate(DuaatRadio.java:52)
  </code></pre>
  
  <p>that is the line mentioned above.</p>
  
  <p>I am unclear exactly how I miscoded the dropdown list that produced the error.</p>
  
  <p>*** let me clarify: the channel selection in the drop down list is defined in an array list (in an xml) that lists all the channels.
  The adapter in code takes the list and is supposed to populate it. However - it appears it is not being populated and thus the error.</p>
  
  <p>It was working in a stand alone app just fine, but when i try to make it work in an intent spawned from a fragment (on a button click), I get the error listed above.</p>
  
  <p>**** UPDATE:  Full code ****</p>
  
  <p>Here is the code for the intent (in full):</p>
  
  <pre><code>import android.annotation.TargetApi;
  import android.app.Activity;
  import android.media.AudioManager;
  import android.media.MediaPlayer;
  import android.media.MediaPlayer.OnPreparedListener;
  import android.os.Build;
  import android.os.Bundle;
  import android.os.Handler;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.SeekBar;
  import android.widget.Spinner;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.io.IOException;
  import java.util.Arrays;
  import java.util.concurrent.TimeUnit;
  
  import static android.R.layout.simple_spinner_dropdown_item;
  import static blackstone.software.sunnahboxtvmenu.R.string.app_name;
  
  /**
   * Created by ironmantis7x on 10/26/15.
   */
  public class DuaatRadio extends Activity implements AdapterView.OnItemSelectedListener, OnPreparedListener {
  
      private MediaPlayer mediaPlayer;
      public TextView songName, duration;
      private double timeElapsed = 0, finalTime = 0;
      private int forwardTime = 2000, backwardTime = 2000;
      private Handler durationHandler = new Handler();
      private SeekBar seekbar;
      //String url = "http://radio.miraath.net:7000";
      //String url = new String[]{"http://radio.miraath.net:7000", "http://radio.miraath.net:7010", "http://radio.miraath.net:7020", "http://radio.miraath.net:7030","http://radio.miraath.net:7040", };
      String url;
      TextView radioInfo;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          //set the layout of the Activity
          setContentView(R.layout.activity_main);
          Spinner dropdown = (Spinner)findViewById(R.id.spinner1);
          String[] items = new String[]{"Masjid Tawheed Radio", "Masjid Rahmah Radio", "1st Muslim Mosque Radio", "Germantown Masjid Radio", "MPUBS Radio", "UK Dawah Radio"};
          String[] radioDescription = new String[]{"Masjid Tawheed (Atlanta, GA) lectures", "Masjid Rahmah (New Jersey) lectures", "1st Muslim Masjid (Pittsburgh, PA) lectures", "Germantown Masjid (Philadelphia, PA) lectures", "MPUBS (Trinadad and Tabago) lectures", "UK lectures"};
          ArrayAdapter&lt;String&gt; adapter;
          adapter = new ArrayAdapter&lt;String&gt;(this, simple_spinner_dropdown_item, items);
          dropdown.setAdapter(adapter);
          dropdown.setOnItemSelectedListener(this);
          int channel = Arrays.asList((getResources().getStringArray(R.array.radios_array))).indexOf(app_name);
  
          //initialize views
          initializeViews();
      }
  
      public void initializeViews(){
          songName = (TextView) findViewById(R.id.songName);
          radioInfo = (TextView) findViewById(R.id.radioInfo);
          mediaPlayer = new MediaPlayer();
          mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
          finalTime = mediaPlayer.getDuration();
          //duration = (TextView) findViewById(R.id.songDuration);
          seekbar = (SeekBar) findViewById(R.id.seekBar);
          songName.setText("Dawah Radio 24-7-12");
  
          seekbar.setMax((int) finalTime);
          seekbar.setClickable(false);
      }
  
      public void onItemSelected(AdapterView&lt;?&gt; parent, View v, int position, long id) {
          //mediaPlayer.release();
  
          switch (position) {
  
              case 0:
                  // Whatever you want to happen when the first item gets selected
                  //mediaPlayer.release();
                  //url = "http://radio.miraath.net:7000";
                  url = "http://api.spreaker.com/listen/episode/6883149/shoutcast?force_http=true";
                  radioInfo.setText("Masjid Al-tawheed Radio");
                  Toast.makeText(getApplicationContext(), url, Toast.LENGTH_LONG).show();
                  break;
              case 1:
                  // Whatever you want to happen when the second item gets selected
                  //mediaPlayer.release();
                  url = "http://api.spreaker.com/listen/episode/6888856/shoutcast?force_http=true";
                  radioInfo.setText("Masjid Rahmah (New Jersey)");
                  Toast.makeText(getApplicationContext(), url, Toast.LENGTH_LONG).show();
                  break;
              case 2:
                  // Whatever you want to happen when the thrid item gets selected
                  //mediaPlayer.release();
                  //url = "http://radio.miraath.net:7020";
                  url = "http://api.spreaker.com/listen/episode/6877902/shoutcast?force_http=true";
                  radioInfo.setText("al-Masjid al-Awwal(Pittsburgh)");
                  Toast.makeText(getApplicationContext(), url, Toast.LENGTH_LONG).show();
                  break;
  
              case 3:
                  // Whatever you want to happen when the thrid item gets selected
                  //mediaPlayer.release();
                  url = "http://api.spreaker.com/listen/episode/6545744/shoutcast?force_http=true";
                  radioInfo.setText("Germantown Masjid (Philadelphia)");
                  Toast.makeText(getApplicationContext(), url, Toast.LENGTH_LONG).show();
                  break;
              case 4:
                  // Whatever you want to happen when the thrid item gets selected
                  //mediaPlayer.release();
                  url = "http://mixlr.com/mpubs/showreel/those-who-rectify-themselves-and-the-people-when-the-people-become-corrupt-by-shaykh-mustafa-mubram/";
                  radioInfo.setText("MPUBS (Trinadad and Tabago)");
                  Toast.makeText(getApplicationContext(), url, Toast.LENGTH_LONG).show();
                  break;
  
              case 5:
                  // Whatever you want to happen when the thrid item gets selected
                  //mediaPlayer.release();
                  //url = "http://radio.miraath.net:7040";
                  url = "http://37.59.4.122:7040";
                  radioInfo.setText("UK lectures");
                  Toast.makeText(getApplicationContext(), url, Toast.LENGTH_LONG).show();
                  break;
          }
  
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
      }
  
      // play mp3 song
      public void play(View view)
      {
          if (!mediaPlayer.isPlaying())
          {
              Toast.makeText(getApplicationContext(), "Radio selected. Buffering Now...", Toast.LENGTH_LONG).show();
              Toast.makeText(getApplicationContext(), "This may take a few moments. Please wait ...", Toast.LENGTH_LONG).show();
          }
  
          duration = (TextView) findViewById(R.id.songDuration);
          try
          {
              if (mediaPlayer.isPlaying())
              {
                  mediaPlayer.stop();
                  mediaPlayer.reset();
                  //mediaPlayer.release();
                  mediaPlayer.setDataSource(url);
                  mediaPlayer.setOnPreparedListener(this);
                  mediaPlayer.prepareAsync();
              }
  
              else if (!mediaPlayer.isPlaying()) {
                  mediaPlayer.setDataSource(url);
                  mediaPlayer.setOnPreparedListener(this);
                  mediaPlayer.prepareAsync();
              }
          }
  
          catch (IllegalArgumentException e)
          {
              Toast.makeText(getApplicationContext(), "Radio not Available. Please try again Later.", Toast.LENGTH_LONG).show();
  
          } catch (SecurityException e) {
              Toast.makeText(getApplicationContext(), "Radio not Available. Please try again Later.", Toast.LENGTH_LONG).show();
  
          } catch (IllegalStateException e) {
              Toast.makeText(getApplicationContext(), "Radio not Available. Please try again Later.", Toast.LENGTH_LONG).show();
  
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  
      //handler to change seekBarTime
      private Runnable updateSeekBarTime = new Runnable() {
          @TargetApi(Build.VERSION_CODES.GINGERBREAD)
          public void run() {
              //get current position
              timeElapsed = mediaPlayer.getCurrentPosition();
              //set seekbar progress
              seekbar.setProgress((int) timeElapsed);
              //set time remaing
              double timeRemaining = finalTime - timeElapsed;
              duration.setText(String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes((long) timeRemaining), TimeUnit.MILLISECONDS.toSeconds((long) timeRemaining) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) timeRemaining))));
              //repeat yourself that again in 100 miliseconds
              durationHandler.postDelayed(this, 100);
          }
      };
  
      // pause mp3 song
      public void pause(View view) {
  
          Toast.makeText(getApplicationContext(), "Audio Paused ...", Toast.LENGTH_LONG).show();
          mediaPlayer.reset();
      }
  
      // go forward at forwardTime seconds
      public void forward(View view) {
          //check if we can go forward at forwardTime seconds before song endes
          if ((timeElapsed + forwardTime) &lt;= finalTime) {
              timeElapsed = timeElapsed + forwardTime;
  
              //seek to the exact second of the track
              mediaPlayer.seekTo((int) timeElapsed);
          }
      }
  
      // go backwards at backwardTime seconds
      public void rewind(View view) {
          //check if we can go back at backwardTime seconds after song starts
          if ((timeElapsed - backwardTime) &gt; 0) {
              timeElapsed = timeElapsed - backwardTime;
  
              //seek to the exact second of the track
              mediaPlayer.seekTo((int) timeElapsed);
          }
      }
  
      @Override
      public void onPrepared(MediaPlayer mp) {
          mediaPlayer.start();
          timeElapsed = mediaPlayer.getCurrentPosition();
          seekbar.setProgress((int) timeElapsed);
          durationHandler.postDelayed(updateSeekBarTime, 100);
  
      }
  
  }
  </code></pre>
  
  <p>Thanks.</p>
  
  <p>ironmantis7x</p>