2013-10-18 28 views
0

我开始加入声音splash.java但IM得到一个错误,我也认为一切都很好,所以你可能会看到它,并帮助我与我会真的感激Android开发添加声音错误

错误即时得到的是:

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, 

上线

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

我的计划是:

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(); 

} 



} 

如果你能知道什么是错误以及如何解决这个问题,我将会非常棒。

+0

你需要传递一个上下文:http://stackoverflow.com/questions/12154951/android-mediaplayer-create –

+0

@JustinJasmann OP是通过'Splash.this'传递'Context' – codeMagic

+1

@justin请发布完整的logcat,你使用的代码是正确的。 –

回答

0

问题是,正在使用错误的id,所以应用程序在这里尝试使用哪个constructor而感到困惑。

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

不是正确的id。相反,它需要的是

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

MediaPlayer

由于语法出现(使用Context, reaourceid)是正确的constructor但应用程序试图使用不同constructor,这使我相信,resourceid是不正确的......以防它可以帮助任何有类似问题的人。