Why I am getting an Error No suitable constructor found for MediaController(ClassNAme )?

2015-08-21 android

Hi All I am new to Android, I am adding Controller to VideoView. Why I am getting below Error.

Error:(51, 41) error: no suitable constructor found for MediaController(ClassNAme )
constructor MediaController.MediaController(Context) is not applicable
(actual argument ClassNAme cannot be converted to Context by method invocation conversion)
constructor MediaController.MediaController(Context,boolean) is not applicable
(actual and formal argument lists differ in length)
constructor MediaController.MediaController(Context,AttributeSet) is not applicable
(actual and formal argument lists differ in length)

****Please Find the below Code below I have ClassName as below****

  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_picturedetail, container, false);

        Bundle b = getArguments();
        Drawable d;
        am = getActivity().getAssets();
        PictDictDetails pd = (PictDictDetails) b.getSerializable("pictobj");
        ImageView iv = (ImageView)v.findViewById(R.id.iv_picture);
        VideoView vi = (VideoView)v.findViewById(R.id.iv_video);
        TextView tv = (TextView)v.findViewById(R.id.tv_picture_name);
        String path = pd.getPath();

       MediaController mediaController1 = new MediaController(this);
       mediaController1.setAnchorView(vi);
       vi.setMediaController(mediaController1);
       String uri = path;
       vi.setVideoURI(Uri.parse(uri));

        vi.start();

Please Find the complete code

public class ClassName extends Fragment {

AssetManager am;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
}

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

    Bundle b = getArguments();
    Drawable d;
    am = getActivity().getAssets();
    PictDictDetails pd = (PictDictDetails) b.getSerializable("pictobj");
    ImageView iv = (ImageView)v.findViewById(R.id.iv_picture);
    VideoView vi = (VideoView)v.findViewById(R.id.iv_video);
    TextView tv = (TextView)v.findViewById(R.id.tv_picture_name);
    String path = pd.getPath();
    String name = pd.getName();
    String uri = path;
    vi.setVideoURI(Uri.parse(uri));

    vi.start();
  MediaController mediaController1 = new MediaController(this);
  mediaController1.setAnchorView(vi);
  vi.setMediaController(mediaController1);


    try
    {  
        InputStream ims = am.open(path);
        d = Drawable.createFromStream(ims, null);
        iv.setImageDrawable(d);
    }
    catch(IOException e)
    {
        e.printStackTrace();
    }
    tv.setText(name);
    return v;
}

@Override
public void onDestroyView() {
    super.onDestroyView();
}

}

Answers

Somewhere in your code (one of the java files) you have created a custom class named "ClassNAme" and I think that you have tried to user the mediaController constructor to create your instance.

You should declare your own custom constructor for this class, unless it is a media controller (in which case make sure it's a subclass of MediaController by using extends).

Related