音乐线程怎么样?

时间:2015-05-10 12:21:09

标签: android nullpointerexception background-music

我正在尝试开发一款应用程序,当您进入主屏幕时,您可以听到音乐,直到您进入其他活动。没什么作用,我不知道为什么...... 我的代码:

public class MainActivity extends Activity {
Button jugar, preferencias, acercade, maximo, salir;
Vibrator v;
Boolean isVibrar,sonido;
MediaPlayer sonidoJuego;
ThreadSonido threadSonido;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_land);
    v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    isVibrar = sharedPref.getBoolean("vibracion", false);
    sonido=sharedPref.getBoolean("musica", true);


    if(sonido==true){
        threadSonido.start();
    }else{
        threadSonido.stop();
    }



}
public void dentroJuego(View view) {
    if (isVibrar==true) {
        v.vibrate(100);
    }
    Intent i = new Intent(MainActivity.this, AngryJuego.class);
    startActivity(i);
    this.finish();
}

public void salir(View view) {
    sonidoJuego.stop();
    finish();
}

public void preferencias(View view) {
    if (isVibrar==true) {
        v.vibrate(100);
    }

    Intent i = new Intent(MainActivity.this, Preferencias.class);
    startActivity(i);
}

public void maximosRegistros(View view) {
    if (isVibrar==true) {
        v.vibrate(100);
    }
    Intent i = new Intent(MainActivity.this, MaximosRegistros.class);
    startActivity(i);
}

public void lanzarAcercaDe(View view) {
    if (isVibrar==true) {
        v.vibrate(100);
    }
    Intent i = new Intent(this, AcercaDe.class);
    startActivity(i);
}
public void recargar(){
    Intent i= this.getIntent();
    finish();
    startActivity(i);
}
@Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
    finish();
}


public class ThreadSonido extends Thread {


    @Override
    public void run() {


        sonidoJuego=MediaPlayer.create(getBaseContext(),R.raw.gaitas);
        sonidoJuego.setLooping(true);
        sonidoJuego.start();


    }

}

}

和日志

05-10 14:08:23.800:E / AndroidRuntime(12283):致命异常:主要 05-10 14:08:23.800:E / AndroidRuntime(12283):java.lang.RuntimeException:无法启动活动ComponentInfo {com.sergiochuky.angryfaba / com.example.game.MainActivity}:java.lang.NullPointerException

0 个答案:

没有答案