0

我在運行應用程序並打開它崩潰的活動時使用了Recyclerview。我是android新手,因此我無法使用SQlite實現Recyclerview,因爲我在Internet上執行了一些代碼在我的代碼實現,但我的應用程序崩潰,在Recycler視圖片段上的錯誤

日誌

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; 

請幫助 我想訪問數據庫淡水河谷顯示爲卡

回答

1

更換

mRecyclerView = (RecyclerView) mRecyclerView.findViewById(R.id.rv_recycler_view);

mRecyclerView = (RecyclerView) rootView.findViewById(R.id.rv_recycler_view);

+0

哦,我see..i忘記的Cuz的片段..anyway感謝鏈接rootview您幫助工作.. – Navin