Android Sound无法解析方法

时间:2015-09-23 05:33:02

标签: android media-player android-mediaplayer

想要制作带有片段的音板,我正在使用此示例代码并添加到其上。 https://github.com/Z0NEN/Slide_Menu

我收到错误“此R.raw。for”无法解析创建方法(app.zOnen.slidemenu.menue1_Fragment,int) 我也在findViewByID上得到它。

我有一段时间没有使用Android Studio,我制作了一个类似程序的音板,之前一切正常。

  package app.z0nen.slidemenu;

import android.app.Fragment;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;


public class menu1_Fragment extends Fragment {
    View rootview;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootview = inflater.inflate(R.layout.menu1_layout, container, false);
        return rootview;

        final MediaPlayer assinstrumentmp = MediaPlayer.create(this, R.raw.assinstrument);

        Button assinstrument = (Button)this.findViewById(R.id.assinstrument);
        assinstrument.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(assinstrumentmp.isPlaying()) {
                    assinstrumentmp.seekTo(0);
                }
                else {
                    assinstrumentmp.start();
                }
            }
        });

        final MediaPlayer asscootermp = MediaPlayer.create(this, R.raw.assscooter);

        Button assscooter = (Button)this.findViewById(R.id.assscooter);
        assinstrument.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (asscootermp.isPlaying()) {
                    asscootermp.seekTo(0);
                } else {
                    asscootermp.start();
                }
            }
        });

    }
}

1 个答案:

答案 0 :(得分:0)

return始终是任何方法的最后陈述,因此请使用return rootview;作为onCreateView方法的最后一行:

 @Override
    public View onCreateView(LayoutInflater inflater, 
                       ViewGroup container, Bundle savedInstanceState) {
        rootview = inflater.inflate(R.layout.menu1_layout, container, false);

      // add your all code here....     

     return rootview; //<< return here
    }