While i am running the code below i am getting the adapter error,i tried solving it by seeing youtube videos ....still its not working ,its showing that adapter is abstract and so the error is there.which i have attached below.plz give the most relevent solution to this problem.
this is my GridAdapter.java code
public class GridAdapter extends RecyclerView.Adapter<GridAdapter.ViewHolder> {
List<String>titles;
List<Integer>images;
LayoutInflater inflater;
public GridAdapter(Context context,List<String>titles,List<Integer>images){
this.titles = titles;
this.images = images;
this.inflater = LayoutInflater.from(context);
}
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.intoduction,parent,false);
return new ViewHolder(view);
}
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.titles.setText(titles.get(position));
holder.images.setImageResource(images.get(position));
}
public int getItemCount() {
return titles.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
TextView titles;
ImageView images;
public ViewHolder(@NonNull View itemView) {
super(itemView);
titles = itemView.findViewById(R.id.textView15);
images = itemView.findViewById(R.id.imageView4);
}
}
}
this is my MainActivity2.java code
public class MainActivity2 extends AppCompatActivity {
RecyclerView recycleview1;
List<String> titles;
List<Integer>images;
Adapter GridAdapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.intropage);
recycleview1 = findViewById(R.id.recycleview1);
titles = new ArrayList<>();
images = new ArrayList<>();
titles.add("first item");
titles.add("second item");
titles.add("third item");
titles.add("fourth item");
images.add(R.drawable.bheeshma);
images.add(R.drawable.sadak2);
images.add(R.drawable.tanhaji);
images.add(R.drawable.thappad);
GridAdapter = **new Adapter(this,titles,images);**
GridLayoutManager gridLayoutManager = new
GridLayoutManager(this,2,GridLayoutManager.VERTICAL,false);
recycleview1.setLayoutManager(gridLayoutManager);
recycleview1.setAdapter(**GridAdapter**);
}
}
this is the error i am getting
Adapter is abstract; cannot be instantiated
GridAdapter = new Adapter(this,titles,images);