Siddharth Venu Siddharth Venu - 1 year ago 85
Java Question

"this" keyword doesn't return Context

I defined my own Custom

, named
, like this:

public class WordAdapter extends ArrayAdapter<Word> {
Context context;

public WordAdapter(Context context, ArrayList<Word> words) {
super(context, 0, words);
this.context = context;

public View getView(int position, View convertView, ViewGroup parent) {

// Check if the existing view is being reused, otherwise inflate the view
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);

Word currentWord = getItem(position);

TextView miwok = (TextView) listItemView.findViewById(;

TextView english = (TextView) listItemView.findViewById(;

return listItemView;

I need it in a class and it is used like this:

public class NumbersActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {

ArrayList<Word> words = new ArrayList<>();
words.add(new Word("lutti","one"));
words.add(new Word("otiiko","two"));
words.add(new Word("toldokosu","three"));
words.add(new Word("oyyisa","four"));
words.add(new Word("massoka","five"));
words.add(new Word("temmoka","six"));
words.add(new Word("kenekaku","seven"));
words.add(new Word("kawinta","eight"));
words.add(new Word("wo'e","nine"));
words.add(new Word("na'aacha","ten"));

WordAdapter itemsAdapter = new WordAdapter(this, words);

ListView listView = (ListView) findViewById(;



But it gives error in the line
WordAdapter itemsAdapter = new WordAdapter(this, words);
, saying

WordAdapter (android.content.Context ArrayList) cannot be applied to ArrayList


dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile ''
compile ''
compile ''

Answer Source

I can tell there is no problem in your code. AppCompatActivity is Context itself. So, passing "this" should work anyway.

So as I can see, there is dependency conflict. If you have added appcompat dependency, you don't have to add support V4 dependency too, because supportv4 package comes with appcompat dependency already.

What would I suggest is to remove support v4 dependency and sync with gradle again. it should be fine then, Even though if it does not work, just do one more step ie. Click on File -> Invalidate/Cache Restart -> Click on Invalidate cahe and Restart.

Now I am pretty much sure, that problem will not be there.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download