发布运行时错误媒体播放器

时间:2012-07-22 16:23:39

标签: android eclipse media-player

我尝试播放音乐应用程序时出现以下错误:

07-22 15:44:14.936: W/KeyCharacterMap(277): No keyboard for id 0
07-22 15:44:14.936: W/KeyCharacterMap(277): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
07-22 15:44:17.546: D/AndroidRuntime(277): Shutting down VM
07-22 15:44:17.546: W/dalvikvm(277): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-22 15:44:17.596: E/AndroidRuntime(277): FATAL EXCEPTION: main
07-22 15:44:17.596: E/AndroidRuntime(277): java.lang.RuntimeException: Unable to pause activity {com.testasaf.asaf.guttman/com.testasaf.asaf.guttman.Intro}: java.lang.NullPointerException
07-22 15:44:17.596: E/AndroidRuntime(277):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3348)
07-22 15:44:17.596: E/AndroidRuntime(277):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3305)
07-22 15:44:17.596: E/AndroidRuntime(277):  at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3288)
07-22 15:44:17.596: E/AndroidRuntime(277):  at android.app.ActivityThread.access$2500(ActivityThread.java:125)
07-22 15:44:17.596: E/AndroidRuntime(277):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
07-22 15:44:17.596: E/AndroidRuntime(277):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 15:44:17.596: E/AndroidRuntime(277):  at android.os.Looper.loop(Looper.java:123)
07-22 15:44:17.596: E/AndroidRuntime(277):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-22 15:44:17.596: E/AndroidRuntime(277):  at java.lang.reflect.Method.invokeNative(Native Method)
07-22 15:44:17.596: E/AndroidRuntime(277):  at java.lang.reflect.Method.invoke(Method.java:521)
07-22 15:44:17.596: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-22 15:44:17.596: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-22 15:44:17.596: E/AndroidRuntime(277):  at dalvik.system.NativeStart.main(Native Method)
07-22 15:44:17.596: E/AndroidRuntime(277): Caused by: java.lang.NullPointerException
07-22 15:44:17.596: E/AndroidRuntime(277):  at com.testasaf.asaf.guttman.Intro.onPause(Intro.java:41)
07-22 15:44:17.596: E/AndroidRuntime(277):  at android.app.Activity.performPause(Activity.java:3842)
07-22 15:44:17.596: E/AndroidRuntime(277):  at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1190)
07-22 15:44:17.596: E/AndroidRuntime(277):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3335)
07-22 15:44:17.596: E/AndroidRuntime(277):  ... 12 more
07-22 15:44:19.685: I/Process(277): Sending signal. PID: 277 SIG: 9

这是代码

package com.testasaf.asaf.guttman;

import com.testasaf.asaf.guttman.R;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class Intro extends Activity {
    MediaPlayer someSong;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.intro);
        MediaPlayer someSong= MediaPlayer.create(Intro.this,R.raw.music);//create an media player object
        someSong.start();//start the music
        Thread timer= new Thread(){//create new  thread with anonymous class
            public void run(){
                try{
                    sleep(5000);//5 second pause
                }catch(Exception e){
                    e.printStackTrace();//print the stack trace if hvae an error
                }finally{
                    Intent saIntent=new Intent("com.testasaf.asaf.guttman.STARTINGPOINT");
                    startActivity(saIntent);//Calling the other activity
                }
            }
        };
        timer.start();
    }
    protected void onPause() {
        super.onPause();
        someSong.release();//release the song
        finish();
    }
}

我认为错误在发布方法中,我在内联网和StackOverflow中搜索但我没有找到任何答案。

1 个答案:

答案 0 :(得分:2)

替换

MediaPlayer someSong= MediaPlayer.create(Intro.this,R.raw.music);//create an media player object

someSong= MediaPlayer.create(Intro.this,R.raw.music);//create an media player object