Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialkenikeako
1,785 PointslistAdapter is Abstract? Cannot instantiate
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//second is the view group where the fragment_list is being added
//Fragments can be added in the XML of an activity or use the view group as a place holder
View view = inflater.inflate(R.layout.fragment_list, container, false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.listRecyclerView);
ListAdapter listAdapter = new ListAdapter();
recyclerView.setAdapter(listAdapter);
return view;
I am following the instructions in the video. I am getting the message that the listAdapter cannot be instantiated because its abstract? Why is that the case?
2 Answers
Seth Kroger
56,414 PointsThere are 2 possibilities that come to mind. 1) Since your custom adapter class is called ListAdapter and there is also an Android OS class/interface called ListAdapter it's possible you imported the wrong one. 2) Your ListAdapter extends an abstract class and you need to override all the required methods or your ListAdapter class will be abstract as well, though that should show an error in ListAdapter.
kenikeako
1,785 PointsI figured it out. Thanks :)
kenikeako
1,785 Pointskenikeako
1,785 PointsHello, I'm pretty sure I implemented the right ListAdapter.
And all the required methods are overwritten. This is what I have for the listAdapter class
public class ListAdapter extends RecyclerView.Adapter { @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
}