fr4n
fr4n

Reputation: 755

Custom ListView - cannot instantiate the type ListAdapter

I have this code:

public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   ListView lv = (ListView) findViewById(R.id.lvResult);
   ListAdapter listAdapter = new ListAdapter(Prueba.this, imageList, list1, list2);
   lv.setAdapter(listAdapter);
}

And it gives an Error:
Cannot instantiate the type ListAdapter

In the same package, I have created a class called ListAdapter.java with its code.
I don't know what that error means.

Upvotes: 2

Views: 7909

Answers (2)

Mark Allison
Mark Allison

Reputation: 21909

ListAdapter is also a class in the android.widget package. It is possible that you are importing this, and this is trying to be instantiated rather than your local ListAdapter class.

Your options are:

  1. Try renaming your ListAdapter class to something different, to remove the possible conflict.
  2. Remove import android.widget.ListAdapter; or import android.widget.*; from your code.
  3. fully qualify the class that you want to use (i.e. com.mycompany.ListAdapter)

Upvotes: 11

Android
Android

Reputation: 9023

See Custom Listview.

Upvotes: 0

Related Questions