当我运行应用程序并打开它崩溃的活动时,我在片段上使用Recyclerview。我是android的新手所以我无法使用SQlite实现Recyclerview,因为我在互联网上执行了一些代码并在我的代码中实现但是我的应用程序崩溃了
日志
02-25 11:53:20.362 19942-19942/com.navinkadlak.typroject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.navinkadlak.typroject, PID: 19942
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.support.v7.widget.RecyclerView.findViewById(int)' on a null object reference
at com.navinkadlak.typroject.Employees.onCreateView(Employees.java:58)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1025)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1545)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:760)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:17915)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1075)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:760)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:760)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2731)
at android.view.View.measure(View.java:17915)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2414)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1416)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1640)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1294)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6614)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:800)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:572)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:786)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5706)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(Zygote
我的代码显示错误
helpher=new DatabaseHelper(getActivity());
dbList= new ArrayList<EmployeeDetails>();
dbList = helpher.getDataFromDB();
mRecyclerView = (RecyclerView) mRecyclerView.findViewById(R.id.rv_recycler_view);
mRecyclerView.setHasFixedSize(true);
// use a linear layout manager
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
// specify an adapter
mAdapter = new MyAdapter(getActivity(),dbList);
mRecyclerView.setAdapter(mAdapter);
return rootView;
请帮忙 我正在尝试访问数据库vale以显示到卡
答案 0 :(得分:2)
替换
mRecyclerView = (RecyclerView) mRecyclerView.findViewById(R.id.rv_recycler_view);
带
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.rv_recycler_view);