Ashley
Ashley

Reputation: 41

android Mediaplayer can not work in emulator

I'm begginer in android Programming My Question is...

I wanted to play backgroud Music. So I read a code like this


public class Welcome extends Activity {
    /** Called when the activity is first created. */

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

        player=MediaPlayer.create(Welcome.this, R.raw.song);
        player.start(); 

But this code doesn't work in emulator. Error occured...

My Logcat is here..


03-05 15:36:36.588: ERROR/AndroidRuntime(954): FATAL EXCEPTION: main
03-05 15:36:36.588: ERROR/AndroidRuntime(954): java.lang.RuntimeException: Unable to start activity ComponentInfo{younkyung.app.lord_of_spelling/younkyung.app.lord_of_spelling.Welcome}: java.lang.NullPointerException
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at android.os.Looper.loop(Looper.java:123)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at java.lang.reflect.Method.invokeNative(Native Method)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at java.lang.reflect.Method.invoke(Method.java:521)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at dalvik.system.NativeStart.main(Native Method)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): Caused by: java.lang.NullPointerException
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at younkyung.app.lord_of_spelling.Welcome.onCreate(Welcome.java:25)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-05 15:36:36.588: ERROR/AndroidRuntime(954):     ... 11 more

I cannot understand what's wrong... Please Help..! ...

Upvotes: 3

Views: 2998

Answers (1)

Dre
Dre

Reputation: 4329

You need to use one of the supported file formats. WMA is not one of them.

Upvotes: 1

Related Questions