title: Case and switch method to stop and start Android media player
body: <p>I have a spinner that you can choose which quality you prefer to stream, and when selected you have to press stop button to stop the player, then select your stream, then you have to select play button to tune into the stream you selected. Can I do this automatically? This is the code I have.</p>
  
  <pre><code>@Override
  public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
  
  int position = spinner.getSelectedItemPosition();
  switch (position){
  case 0:
      path = ("URL TO STREAM");
      break;
  
  case 1:
      path = ("URL TO STREAM");
      break;
  
  }
  
  
        }
  
        @Override
         public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
     // TODO Auto-generated method stub
  
        }
       }
  </code></pre>
  
  <p>When I use this code</p>
  
  <pre><code>@Override
  public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
  
  int position = spinner.getSelectedItemPosition();
  switch (position){
  case 0:
              mp.stop();
      path = ("URL TO STREAM");
      mp.start();
              break;
  
  case 1:
              mp.stop();
      path = ("URL TO STREAM");
      mp.start();
              break;
  
  }
  
  
        }
  
        @Override
         public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
     // TODO Auto-generated method stub
  
        }
       }
  </code></pre>
  
  <p>My app crashes and not sure why the code above won't work, I don't get errors in Eclipse, essentially I'm trying to stop media player, switch URI, and start media player, when user selects high or low quality from spinner.</p>
  
  <p>Here is my logcat:</p>
  
  <pre><code>03-10 18:54:51.041: D/AndroidRuntime(284): &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AndroidRuntime START          
  03-10 18:54:51.041: D/AndroidRuntime(284): CheckJNI is ON
  03-10 18:54:51.201: D/AndroidRuntime(284): --- registering native functions ---
  03-10 18:54:51.851: D/AndroidRuntime(284): Shutting down VM
  03-10 18:54:51.861: D/dalvikvm(284): Debugger has detached; object registry had 1      entries
  03-10 18:54:51.871: I/AndroidRuntime(284): NOTE: attach of thread 'Binder Thread #3'    failed
  03-10 18:54:52.251: D/AndroidRuntime(292): &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AndroidRuntime START     &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  03-10 18:54:52.251: D/AndroidRuntime(292): CheckJNI is ON
  03-10 18:54:52.421: D/AndroidRuntime(292): --- registering native functions ---
  03-10 18:54:53.071: I/ActivityManager(58): Force stopping package com.slaviccenter.radio    uid=10037
  03-10 18:54:53.081: I/Process(58): Sending signal. PID: 273 SIG: 9
  03-10 18:54:53.165: I/WindowManager(58): WIN DEATH: Window{4606c8b0     com.slaviccenter.radio/com.slaviccenter.radio.MainActivity paused=false}
  03-10 18:54:53.181: I/UsageStats(58): Unexpected resume of com.android.launcher while   already resumed in com.slaviccenter.radio
  03-10 18:54:53.211: W/InputManagerService(58): Got RemoteException sending    setActive(false) notification to pid 273 uid 10037
  03-10 18:54:53.271: I/ActivityManager(58): Starting activity: Intent {    act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000    cmp=com.slaviccenter.radio/.MainActivity }
  03-10 18:54:53.271: D/AndroidRuntime(292): Shutting down VM
  03-10 18:54:53.291: D/dalvikvm(292): Debugger has detached; object registry had 1 entries
  03-10 18:54:53.321: I/dalvikvm(292): JNI: AttachCurrentThread (from ???.???)
  03-10 18:54:53.321: I/AndroidRuntime(292): NOTE: attach of thread 'Binder Thread #3' failed
  03-10 18:54:53.491: I/ActivityManager(58): Start proc com.slaviccenter.radio for activity com.slaviccenter.radio/.MainActivity: pid=299 uid=10037 gids={3003}
  03-10 18:54:53.851: W/ActivityThread(299): Application com.slaviccenter.radio is waiting for the debugger on port 8100...
  03-10 18:54:53.901: I/System.out(299): Sending WAIT chunk
  03-10 18:54:53.921: I/dalvikvm(299): Debugger is active
  03-10 18:54:54.112: I/System.out(299): Debugger has connected
  03-10 18:54:54.112: I/System.out(299): waiting for debugger to settle...
  03-10 18:54:54.311: I/System.out(299): waiting for debugger to settle...
  03-10 18:54:54.511: I/System.out(299): waiting for debugger to settle...
  03-10 18:54:54.711: I/System.out(299): waiting for debugger to settle...
  03-10 18:54:54.921: I/System.out(299): waiting for debugger to settle...
  03-10 18:54:55.127: I/System.out(299): waiting for debugger to settle...
  03-10 18:54:55.322: I/System.out(299): waiting for debugger to settle...
  03-10 18:54:55.521: I/System.out(299): waiting for debugger to settle...
  03-10 18:54:55.732: I/System.out(299): waiting for debugger to settle...
  03-10 18:54:55.933: I/System.out(299): debugger has settled (1369)
  03-10 18:54:56.271: W/WindowManager(58): No window to dispatch pointer action 0
  03-10 18:54:56.421: W/WindowManager(58): No window to dispatch pointer action 1
  03-10 18:55:03.275: W/ActivityManager(58): Launch timeout has expired, giving up wake lock!
  03-10 18:55:03.751: W/ActivityManager(58): Activity idle timeout for HistoryRecord{460b4c78 com.slaviccenter.radio/.MainActivity}
  </code></pre>
  
  <p>After the last line, "Activity idle timeout" The debugger takes me to MainActivity.java</p>
  
  <pre><code>    int position = spinner.getSelectedItemPosition();
  switch (position){
  case 0:
              mp.stop(); &lt;---------DEBUGGER HIGHLIGHTS THIS GREEN
      path = ("URL TO STREAM");
      mp.start();
              break;
  
  case 1:
              mp.stop();
      path = ("URL TO STREAM");
      mp.start();
              break;
  </code></pre>
  
  <p>----NEW LOGCAT--------</p>
  
  <pre><code>03-10 20:45:54.440: W/ActivityThread(375): Application com.slaviccenter.radio is waiting for the debugger on port 8100...
  03-10 20:45:54.460: I/System.out(375): Sending WAIT chunk
  03-10 20:45:54.522: I/dalvikvm(375): Debugger is active
  03-10 20:45:54.661: I/System.out(375): Debugger has connected
  03-10 20:45:54.661: I/System.out(375): waiting for debugger to settle...
  03-10 20:45:54.871: I/System.out(375): waiting for debugger to settle...
  03-10 20:45:55.071: I/System.out(375): waiting for debugger to settle...
  03-10 20:45:55.270: I/System.out(375): waiting for debugger to settle...
  03-10 20:45:55.471: I/System.out(375): waiting for debugger to settle...
  03-10 20:45:55.683: I/System.out(375): waiting for debugger to settle...
  03-10 20:45:55.881: I/System.out(375): waiting for debugger to settle...
  03-10 20:45:56.081: I/System.out(375): waiting for debugger to settle...
  03-10 20:45:56.288: I/System.out(375): waiting for debugger to settle...
  03-10 20:45:56.490: I/System.out(375): waiting for debugger to settle...
  03-10 20:45:56.692: I/System.out(375): debugger has settled (1448)
  03-10 20:46:06.240: D/AndroidRuntime(375): Shutting down VM
  03-10 20:46:06.240: W/dalvikvm(375): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
  03-10 20:46:06.321: E/AndroidRuntime(375): FATAL EXCEPTION: main
  03-10 20:46:06.321: E/AndroidRuntime(375): java.lang.NullPointerException
  03-10 20:46:06.321: E/AndroidRuntime(375):  at com.slaviccenter.radio.MainActivity.onItemSelected(MainActivity.java:296)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at  android.widget.AdapterView.fireOnSelected(AdapterView.java:864)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at android.widget.AdapterView.access$200(AdapterView.java:42)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:830)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at android.os.Handler.handleCallback(Handler.java:587)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at android.os.Handler.dispatchMessage(Handler.java:92)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at android.os.Looper.loop(Looper.java:123)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at android.app.ActivityThread.main(ActivityThread.java:4627)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at java.lang.reflect.Method.invokeNative(Native Method)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at java.lang.reflect.Method.invoke(Method.java:521)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  03-10 20:46:06.321: E/AndroidRuntime(375):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>