ErreC ErreC - 2 years ago 185
Android Question

Cannot resolve constructor adapter with listview using baseadapter

I want to know how to pass the argument to custom adapter . I'm trying to implement a YouTube video list using listview + baseadapter. I'm not sure how to populate properly the listview using the baseadapter
My error is:

Error:(67, 39) error: constructor VideoListAdapter in class YouTubeVideo.VideoListAdapter cannot be applied to given types;
required: Context
found: YouTubeVideo,int,List<Video>
reason: actual and formal argument lists differ in length

Here is my code:

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class YouTubeVideo extends AppCompatActivity {

public static List<Video> MyVideo = new ArrayList<Video>();
public static Map<String, Video> Video_Map = new HashMap<>();

private static void addItem(final Video currentVideo) {
Video_Map.put(currentVideo.getVideoId(), currentVideo);

protected void onCreate(Bundle savedInstanceState) {
Fabric.with(this, new Crashlytics());

//Check for any issues
final YouTubeInitializationResult result = YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(this);

if (result != YouTubeInitializationResult.SUCCESS) {
//If there are any issues we can show an error dialog.
result.getErrorDialog(this, 0).show();


private void populateVideoList() {
addItem(new Video("tttG6SdnCd4", "Open in the YouTube App"));
addItem(new Video("x-hH_Txxzls", "Open in the YouTube App in fullscreen"));
addItem(new Video("TTh_qYMzSZk", "Open in the Standalone player in fullscreen"));
addItem(new Video("tttG6SdnCd4", "Open in the Standalone player in \"Light Box\" mode"));
addItem(new Video("x-hH_Txxzls", "Open in the YouTubeFragment"));

private void populateListView() {

ArrayAdapter<Video> adapter = new VideoListAdapter(YouTubeVideo.this, R.layout.video_view, MyVideo);
ListView list = (ListView) findViewById(;
//------------------------------------------------------------------------------------------------------------------- 12/05/16
private class VideoListAdapter extends BaseAdapter implements YouTubeThumbnailView.OnInitializedListener {

private Context mContext;
private Map<View, YouTubeThumbnailLoader> mLoaders;

public VideoListAdapter(final Context context) {
mContext = context;
mLoaders = new HashMap<>();

public int getCount() {
return MyVideo.size();

public Object getItem(int position) {
return MyVideo.get(position);

public long getItemId(int position) {
return position;

//------------------------------------------------------------------------------------------------------------------- 13/05/16
public View getView(int position, View convertView, ViewGroup parent) {
View videoRow = convertView;

VideoHolder holder;

final Video currentVideo = MyVideo.get(position);

if (videoRow == null) {
//Create the row
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
videoRow = inflater.inflate(R.layout.video_view, parent, false);

//Create the video holder
holder = new VideoHolder();

//Set the title
holder.title = (TextView) videoRow.findViewById(;

//Initialise the thumbnail
holder.thumb = (YouTubeThumbnailView) videoRow.findViewById(;
holder.thumb.initialize(mContext.getString(R.string.DEVELOPER_KEY), this);

} else {
//Create it again
holder = (VideoHolder) videoRow.getTag();
final YouTubeThumbnailLoader loader = mLoaders.get(holder.thumb);

//Set the title
if (currentVideo != null) {

if (loader == null) {
//Loader is currently initialising
} else {
//The loader is already initialised
return videoRow;

public void onInitializationSuccess(YouTubeThumbnailView view, YouTubeThumbnailLoader loader) {
mLoaders.put(view, loader);
loader.setVideo((String) view.getTag());

public void onInitializationFailure(YouTubeThumbnailView thumbnailView, YouTubeInitializationResult errorReason) {
final String errorMessage = errorReason.toString();
Toast.makeText(mContext, errorMessage, Toast.LENGTH_LONG).show();

private class VideoHolder {
YouTubeThumbnailView thumb;
TextView title;


Answer Source

I can not find a constructor in VideoListAdapter with three parameters , I think you missed the following constructor in VideoListAdapter

   public VideoListAdapter  (Context context, int layoutResourceId,
     List<Video> myvideos) {
       super(activity, layoutResourceId, myvideos);
       mContext = context;

or replace

  ArrayAdapter<Video> adapter = new VideoListAdapter(YouTubeVideo.this, R.layout.video_view, MyVideo);


  VideoListAdapter adapter = new VideoListAdapter(YouTubeVideo.this);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download