简体   繁体   English

MediaPlayer.create无法解析为一种类型

[英]MediaPlayer.create cannot be resolved to a type

I'm trying to get an mp3 file to play a sound when a button is clicked (Android app). 我正在尝试获取一个mp3文件,以在单击按钮时播放声音(Android应用程序)。 However, despite following tutorials with similar code, I get this error message 'MediaPlayer.create cannot be resolved as a type. 但是,尽管遵循了使用类似代码的教程,但仍收到此错误消息“ MediaPlayer.create无法解析为类型。 I have refreshed the project and cleaned the project and it made no difference. 我已经刷新了该项目并清理了该项目,但没有任何影响。 Here is my code: 这是我的代码:

package com.example.h.a.t;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class Hypo_Info extends Activity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hypo_info);

        final MediaPlayer mediaPlayer = new MediaPlayer.create(this, R.raw.pill_bottle);

        Button a = (Button) findViewById(R.id.treatment_hypo);



        a.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent i = new Intent(Hypo_Info.this, Hypo_Treatment.class);
                startActivity(i);
                mediaPlayer.start();
            }

        });
    }

The problem is the "new" keyword here: 问题是这里的“ new”关键字:

new MediaPlayer.create(this, R.raw.pill_bottle);

because the MediaPlayer.create is a static method. 因为MediaPlayer.create静态方法。

==> remove the new ==>删除new

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM