• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

ArrayAdapter

I am getting problem with this code
public class WordAdapter extends ArrayAdapter<Word>{
@override
public View getView(int position, View convertView, ViewGroup parent) {
return super.getView(position, convertView, parent);
}
}
it is giving me the error
There is no default constructor available in 'android.widget.ArrayAdapter'.
Can anyone help me out.
 
You need to provide a constructor method for your WordAdapter class

Code:
public class WordAdapter extends ArrayAdapter<Word>{
  
  public WordAdapter(Context context, ArrayList<Word> words) {
      super(context, 0, words);
   }

  @override
  public View getView(int position, View convertView, ViewGroup parent) {
    return super.getView(position, convertView, parent);
  }
}
 
Yeah sure. Because you didn't write a constructor method, then the Java compiler automatically writes one for you during the compile process. That is it will generate a default constructor method with no parameters

Code:
public WordAdapter() {
      super();
}

Note that line "super()". That's trying to to call the default constructor method on the super class - ArrayAdapter. And there is no such constructor defined for that class, therefore you get a compiler error.
 
Back
Top Bottom