Реализовано представление рециркулятора, найденное в моих фрагментах уведомлений, при добавлении itesm к тем же фрагментам никаких проблем не возникает, но при попытке добавить элементы из другого фрагмента, который он выдает, возникает ошибка JavaNullPointException.
здесь мой фрагмент, который имеет вид рециркулятора
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View v = inflater.inflate (R.layout.fragment_notificationcict, container, false);
notimodels = new ArrayList<> ();
mRecyclerView = v.findViewById(R.id.notificationsRecycler);
fillNotification (R.drawable.logo, "OCApp", "Welcome to Online Clearance Application,Get cleared now , avoid queing up in offices , save time and money.",+ minutes+"min");
// get data from the notificiation
return v;
}
@Override
public void onStart() {
super.onStart ();
swipeRefreshLayout.setRefreshing(true);
fillNotification (R.drawable.logo, "OCApp", "Welcome to Online Clearance Application,Get cleared now , avoid queing up in offices , save time and money.",+ minutes+"min");
}
public void fillNotification(int mImage, String mtext, String mtext2, String mDate)
{
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager (getContext ());
mAdapter = new NotificationAdapter (notimodels);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
notimodels.add (0,new NotificationModel (mImage,mtext,mtext2,mDate));
}
}
** Когда я пытаюсь вызвать функцию из других фрагментов, таких как TIS Forexample выдает и выдает эту ошибку
Process: com.univibezstudios.ocappservice.ocapp, PID: 3380
java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setHasFixedSize(boolean)' on a null object reference
Проблема в следующем. Эта ошибка отображается, поскольку представление вашего фрагмента еще не создано. Вот почему recyclerview имеет значение null, и вы вызываете метод setHasFixedSize (...) для вашего null recyclerview. но я могу решить любую помощь, ребята