【问题标题】:Android development adding sound errorAndroid开发添加声音错误
【发布时间】:2013-10-18 23:51:40
【问题描述】:

我开始在 splash.java 中添加声音,但我也遇到了错误

我得到的错误是:

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

}



}

如果您能知道错误是什么以及如何解决它,我将非常感激。

【问题讨论】:

  • @JustinJasmann OP 正在传递 ContextSplash.this
  • @justin 请贴出完整的logcat,你使用的代码是正确的。
  • @JustinJasmann 。对不起,我应该对我的程序做些什么修改?
  • 我在尝试这个时实际上没有收到错误。

标签: java android


【解决方案1】:

问题是使用了错误的id,因此应用混淆了constructor 在这里尝试使用的位置。

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

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

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

MediaPlayer

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

【讨论】:

    猜你喜欢
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多