0

I'm starting adding sound to splash.java but im getting an error also I think everything is good so you might see it and help me with that I'm gonna be really greatful

the error im getting is :

Multiple markers at this line
- Syntax error on token ".", class expected after this token
- The method create(Context, Uri) in the type MediaPlayer is not applicable for the arguments     (Splash, 

on the line

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

my program is :

package com.sc.uploader;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;

public class Splash extends Activity {

@Override
protected void onCreate(Bundle IloveU) {
    // TODO Auto-generated method stub
    super.onCreate(IloveU);
    setContentView(R.layout.splash);
    MediaPlayer start = MediaPlayer.create(Splash.this, R.raw.splashsound); 
    start.start();
    Thread timer = new Thread(){

        public void run(){
            try{
                sleep(5000);

            } catch (InterruptedException e){
                e.printStackTrace();
            }finally {
                Intent openStarting = new       Intent("com.sc.uploader.MAINACTIVITY");
                startActivity(openStarting);
            }

        }

    };
    timer.start();

}



}

if you could know what is the error and how to fix it i will be really greatful .

Scatteril
  • 17
  • 5
  • You need to pass in a Context : http://stackoverflow.com/questions/12154951/android-mediaplayer-create – Justin Jasmann Oct 18 '13 at 15:20
  • @JustinJasmann the OP is passing in `Context` with `Splash.this` – codeMagic Oct 18 '13 at 15:22
  • 1
    @justin please post the full logcat, the code used by you is correct. – Rohan Kandwal Oct 18 '13 at 15:24
  • @JustinJasmann . Im sorry but what modification should I do with my program ? – Scatteril Oct 18 '13 at 15:25
  • I actually don't get an error when I try this out. – Justin Jasmann Oct 18 '13 at 15:35
  • Double check that `splashsound` is the correct `raw resource` (check spelling) and try cleaning your project, "Project --> Clean..." – codeMagic Oct 18 '13 at 15:38
  • @codeMagic I have replaced splashsound with the name of the Mp3 like that : start = MediaPlayer.create(Splash.this,R.raw.e); and it works . is it correct way to do it ? or i should use splashsound and look for an answer is better ? – Scatteril Oct 18 '13 at 15:41
  • And what happened? It should be the `resource` in your `raw` folder – codeMagic Oct 18 '13 at 15:42
  • it works . shall i move on with the rest of the program or I should start digging for the old error's solution ? – Scatteril Oct 18 '13 at 15:44
  • We fixed it so you should move on. You had the wrong `resource` `id` which is why the app was confused on which `constructor` you were trying to use...that's the solution. I will post as an answer if you want to accept so it may help others. – codeMagic Oct 18 '13 at 15:46
  • @user2887820 I have posted an answer of how I came to that being the issue. Hopefully it can help. – codeMagic Oct 18 '13 at 15:52

1 Answers1

0

The problem is that the wrong id is being used so the app is confused on which constructor is trying to be used here.

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

was not the proper id. Instead it needed to be

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

MediaPlayer

Since the syntax appeared to be correct (using Context, reaourceid) for the constructor but the app was trying to use a different constructor, this led me to believe that the resourceid was incorrect...in case it can help anyone with a similar issue.

codeMagic
  • 44,549
  • 13
  • 77
  • 93