I just added an intent so that i can move on to the next page upon clicking on one of the item which is present in the recycler view, but i'm getting an error over there, also i have added a Toast message upon the click og the item and that is working fine but the intent is crashing the app. And also i'm adding this code in the adapter not in the main activity. Need some help, thanks
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
if (holder instanceof ItemViewHolder) {
final Notifications notification = notifications.get(position);
final ItemViewHolder viewHolder = (ItemViewHolder) holder;
viewHolder.title.setText(notifications.get(position).getTitle());
viewHolder.description.setText(notifications.get(position).getDescription());
viewHolder.date.setText(notifications.get(position).getDate());
viewHolder.itemView.setBackgroundColor(Color.GRAY);
viewHolder.notificationLay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText((firebaseMain)activity, "Item clicked " + position, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(firebaseMainActivity, NotificationDetails.class);
context.startActivity(intent);
}
});
} else if (holder instanceof LoadingViewHolder) {
LoadingViewHolder loadingViewHolder = (LoadingViewHolder) holder;
loadingViewHolder.progressBar.setIndeterminate(true);
}
}
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.sample.collegeautomation, PID: 1875
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
at android.content.ComponentName.<init>(ComponentName.java:130)
at android.content.Intent.<init>(Intent.java:6082)
at com.app.sample.collegeautomation.firebaseNotifications.firebaseListViewAdapter$3.onClick(firebaseListViewAdapter.java:146)
at android.view.View.performClick(View.java:6597)
at com.balysv.materialripple.MaterialRippleLayout$PerformClickEvent.run(MaterialRippleLayout.java:648)
at com.balysv.materialripple.MaterialRippleLayout$3.onAnimationEnd(MaterialRippleLayout.java:336)
at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:552)
at android.animation.AnimatorSet.endAnimation(AnimatorSet.java:1294)
at android.animation.AnimatorSet.doAnimationFrame(AnimatorSet.java:1079)
at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)