2

こんにちは、私は自分のAndroidプログラムでいくつかのコーディングを行っていました。ここでこのコードを使用して音楽を再生しようとしました。Androidの最低ビルドは2.2で、最高ビルドは4.2.2で、Eclipseを使用してこれを行い、デバイスエミュレーターはnexus 1です

これは地球上で

    MediaPlayer Sound;

これはsetContentViewの下にあります

    Sound = MediaPlayer.create(Splash.this, R.raw.kalimba);
    Sound.start();

これがコード全体です

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer Sound;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Sound = MediaPlayer.create(Splash.this, R.raw.kalimba);
    Sound.start();
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);                    
            } catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent openStartingPoints = new              Intent("com.mysampleapp.simplybel.MainActivity");
                startActivity(openStartingPoints);
            }//this is the end for the finally
        }//this is the end for the run
    };//this is the end for the thread timer
    timer.start();

}//this is the end for the oncreate

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    Sound.release();
    finish();
}


}

誰でもこれで私を助けることができますか?

4

1 に答える 1

0

それはあなたの意図から来ているかもしれません。この意図で正確に何をしようとしていますか?

明示的インテントの正しい構文は、このインテント チュートリアルのようになります。たとえば、 コンテキストはグローバル変数宣言のIntent openStartingPoints=new Intent(context,MainActivity.class);ようにスレッドの外側にある必要があり、onCreate() の内側でインスタンス化して現在のアクティビティのコンテキストに設定する必要があります。Context context;context=this;

別の提案として、変数名は常にキャメルケースで名前を付けて、最初の文字を小文字にする必要があります。

これで何か変わるかどうか教えてください。それ以外は、提供されたコードに問題は見られません。

于 2013-07-25T10:12:43.807 に答える