Я пытаюсь показать список, извлеченный из базы данных firestore, на дочерней вкладке TODAY и WEEK, как показано на изображении общего доступа, но я получаю сообщение об ошибке в этой строке кода.
recyclerView.setLayoutManager(new LinearLayoutManager(c));
Я пытался выяснить, но пока что ничего не найдено, я поделился приведенным ниже кодом, Пожалуйста, помогите мне, если я ошибаюсь, и поправьте меня.Спасибо.
снимок экрана приложения
public class TodaysFixturesFragment
extends Fragment {
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference PostsRef = db.collection("posts");
private FirebaseAuth mauth;
private PostsAdapter adapter;
StorageReference storageReference;
private Button commentsbutton;
RecyclerView recyclerView;
RelativeLayout mParent;
private String mUserID;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//just change the fragment_dashboard
//with the fragment you want to inflate
//like if the class is HomeFragment it should have R.layout.home_fragment
//if it is DashboardFragment it should have R.layout.fragment_dashboard
storageReference = FirebaseStorage.getInstance().getReference().child("profile_pic");
mauth = FirebaseAuth.getInstance();
mUserID = mauth.getCurrentUser().getUid();
// Query query = PostsRef.whereEqualTo("post_author_id", mUserID).whereEqualTo("l3", true);
Query query = PostsRef;
final View view = inflater.inflate(R.layout.fragment_home, container, false);
final FragmentActivity c = getActivity();
LinearLayoutManager layoutManager = new LinearLayoutManager(c);
/*
FirestoreRecyclerOptions<PostsModel> options = new FirestoreRecyclerOptions.Builder<PostsModel>()
.setQuery(query, PostsModel.class)
.build();
adapter = new PostsAdapter(options);
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view_mw_pending);
// recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(c));
recyclerView.setAdapter(adapter);
mParent =view.findViewById(R.id.relative_home1);*/
return inflater.inflate(R.layout.mwpending, null);
}
@Override
public void onStart() {
super.onStart();
adapter.startListening();
}
@Override
public void onStop() {
super.onStop();
adapter.stopListening();
}
}
Подробности Logcat
Process: com.ramneekkashyap.blogapplication.blogapp2, PID: 6115
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.ramneekkashyap.blogapplication.blogapp2.adapters.PostsAdapter.startListening()' on a null object reference
at com.ramneekkashyap.blogapplication.blogapp2.TodaysFixturesFragment.onStart(TodaysFixturesFragment.java:86)
at androidx.fragment.app.Fragment.performStart(Fragment.java:2632)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:915)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManagerImpl.java:1696)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:299)
at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:235)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
at android.view.View.measure(View.java:24955)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7149)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:743)
at com.google.android.material.appbar.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:99)
at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1882)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:813)
at android.view.View.measure(View.java:24955)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:24955)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7149)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:24955)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:24955)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7149)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:743)
at com.google.android.material.appbar.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:99)
at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1882)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:813)
at android.view.View.measure(View.java:24955)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:24955)
at androidx.drawerlayout.widget.DrawerLayout.onMeasure(DrawerLayout.java:1119)
at android.view.View.measure(View.java:24955)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7149)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:24955)
E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7149)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:24955)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7149)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:24955)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7149)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:24955)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7149)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:1029)
at android.view.View.measure(View.java:24955)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3338)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2067)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2366)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1927)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8558)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7094)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
I/Process: Sending signal. PID: 6115 SIG: 9
Process 6115 terminated.