[Android Q&A, Help & Troubleshooting] bizkit1:
Hello guys. I`m working on a app for listening a online radio station. All works great, but i run into a bump using a spinner. Here is my code:

package com.hrupin.streamingmedia;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.hrupin.media.R;

public class StreamingMp3Player extends Activity implements OnClickListener, OnTouchListener, OnCompletionListener, OnBufferingUpdateListener, OnItemSelectedListener{
TextView textMsg, textPrompt;
ImageView imageView;
Spinner spnLocale;
final String textSource = "xxxxxxx.php";
private ImageButton buttonPlayPause;
protected EditText editTextSongURL;

private MediaPlayer mediaPlayer;

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(true);
return true;
}
return super.onKeyDown(keyCode, event);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
finish();
System.exit(0);
}
});

imageView = (ImageView) findViewById(R.id.imagine);
textPrompt = (TextView)findViewById(R.id.textprompt);
textMsg = (TextView)findViewById(R.id.textmsg);
textMsg.post( new Runnable(){

public void run(){

URL textUrl;
try {

textUrl = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
textMsg.setText(stringText);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
}
textMsg.postDelayed(this,(1000*10));
}

});

initView();
spnLocale = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnLocale.setAdapter(adapter);
spnLocale.setOnItemSelectedListener(new StreamingMp3Player());
}

private void initView() {

buttonPlayPause = (ImageButton)findViewById(R.id.ButtonTestPlayPause);
buttonPlayPause.setOnClickListener(this);

editTextSongURL = (EditText)findViewById(R.id.EditTextSongURL);
editTextSongURL.setText("Romantic FM");

mediaPlayer = new MediaPlayer();
mediaPlayer.setOnBufferingUpdateListener(this);
mediaPlayer.setOnCompletionListener(this);
}

public void onClick(View v) {
if(v.getId() == R.id.ButtonTestPlayPause){

try {
mediaPlayer.setDataSource("xxxxxxx:7651");

mediaPlayer.prepare();
} catch (Exception e) {
e.printStackTrace();
}

//mediaFileLengthInMilliseconds = mediaPlayer.getDuration();

if(!mediaPlayer.isPlaying()){
mediaPlayer.start();
//buttonPlayPause.setBackgroundColor(Color.RED);
buttonPlayPause.setImageResource(R.drawable.button_pause);
}else {
mediaPlayer.pause();
buttonPlayPause.setImageResource(R.drawable.button_play);
//System.out.println("Pauza");

}

}
}

public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
if(pos == 1) {
mediaPlayer.pause();
}

}

@SuppressWarnings("rawtypes")
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}

public void onCompletion(MediaPlayer mp) {

buttonPlayPause.setImageResource(R.drawable.button_play);

}

public void onBufferingUpdate(MediaPlayer arg0, int arg1) {
// TODO Auto-generated method stub

}

public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
return false;
}

}

This next code is supposed to stop mediaplayer from playing if i select a specific value from the spinner options:

public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
if(pos == 1) {
mediaPlayer.pause();
}

}

public void onNothingSelected(AdapterView parent) {
// Do nothing.
}

But instead of stopping the mediaplayer it crashes. I get this error from logcat:

05-28 06:34:42.752: E/AndroidRuntime(377): FATAL EXCEPTION: main
05-28 06:34:42.752: E/AndroidRuntime(377): java.lang.NullPointerException
05-28 06:34:42.752: E/AndroidRuntime(377):	at com.hrupin.streamingmedia.StreamingMp3Player.onItemSelected(StreamingMp3Player.java:165)
05-28 06:34:42.752: E/AndroidRuntime(377):	at android.widget.AdapterView.fireOnSelected(AdapterView.java:871)
05-28 06:34:42.752: E/AndroidRuntime(377):	at android.widget.AdapterView.access$200(AdapterView.java:42)
05-28 06:34:42.752: E/AndroidRuntime(377):	at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:837)
05-28 06:34:42.752: E/AndroidRuntime(377):	at android.os.Handler.handleCallback(Handler.java:587)
05-28 06:34:42.752: E/AndroidRuntime(377):	at android.os.Handler.dispatchMessage(Handler.java:92)
05-28 06:34:42.752: E/AndroidRuntime(377):	at android.os.Looper.loop(Looper.java:123)
05-28 06:34:42.752: E/AndroidRuntime(377):	at android.app.ActivityThread.main(ActivityThread.java:3683)
05-28 06:34:42.752: E/AndroidRuntime(377):	at java.lang.reflect.Method.invokeNative(Native Method)
05-28 06:34:42.752: E/AndroidRuntime(377):	at java.lang.reflect.Method.invoke(Method.java:507)
05-28 06:34:42.752: E/AndroidRuntime(377):	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-28 06:34:42.752: E/AndroidRuntime(377):	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-28 06:34:42.752: E/AndroidRuntime(377):	at dalvik.system.NativeStart.main(Native Method)

So can someone tell me what i'm doing wrong? Thanks!