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.i开发者_如何学Cd.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.
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:
- Try renaming your ListAdapter class to something different, to remove the possible conflict.
- Remove
import android.widget.ListAdapter;
orimport android.widget.*;
from your code. - fully qualify the class that you want to use (i.e.
com.mycompany.ListAdapter
)
See Custom Listview.
精彩评论