Recycler View:没有添加addapter;跳过布局

时间:2015-11-14 02:48:36

标签: android android-studio android-recyclerview

首先,我想首先说我阅读了与此问题相关的所有帖子,但到目前为止,他们都没有能够解决这个问题。

我正在关注一个关于Navigation Drawer http://www.android4devs.com/2014/12/how-to-make-material-design-navigation-drawer.html的精彩教程,由于某种原因,我无法让Recycler工作。

这是我初始化它的方式

    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);


    mRecyclerView.setLayoutManager(mLayoutManager);

    mAdapter = new DrawerAdapter(TITLES,ICONS,NAME,EMAIL,PROFILE);

    mRecyclerView.setAdapter(mAdapter);                              // Setting the adapter to RecyclerView

    mRecyclerView.setHasFixedSize(true);                            // Letting the system know that the list objects are of fixed size

错误:

E/RecyclerView: No adapter attached; skipping layout

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.support.v7.widget.RecyclerView$LayoutManager.canScrollVertically()' on a null object reference

可能第二个与第一个有关。

编辑:

  11-14 10:48:53.446 32329-32329/? E/Zygote: MountEmulatedStorage()
11-14 10:48:53.446 32329-32329/? E/Zygote: v2
11-14 10:48:53.446 32329-32329/? I/libpersona: KNOX_SDCARD checking this for 10809
11-14 10:48:53.446 32329-32329/? I/libpersona: KNOX_SDCARD not a persona
11-14 10:48:53.476 32329-32329/? I/SELinux: Function: selinux_compare_spd_ram, SPD-policy is existed. and_ver=SEPF_SM-N9005_5.0 ver=27
11-14 10:48:53.476 32329-32329/? I/SELinux: Function: selinux_compare_spd_ram , priority [1] , priority version is VE=SEPF_SM-N9005_5.0_0027
11-14 10:48:53.476 32329-32329/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
11-14 10:48:53.476 32329-32329/? I/art: Late-enabling -Xcheck:jni
11-14 10:48:53.516 32329-32329/? D/TimaKeyStoreProvider: TimaSignature is unavailable
11-14 10:48:53.526 32329-32329/? D/ActivityThread: Added TimaKeyStore provider
11-14 10:48:53.556 32329-32329/name.company.newapp D/ResourcesManager: creating new AssetManager and set to /data/app/name.company.newapp-1/base.apk
11-14 10:48:53.706 32329-32360/name.company.newapp I/GMPM: App measurement is starting up
11-14 10:48:53.716 32329-32360/name.company.newapp E/GMPM: getGoogleAppId failed with status: 10
11-14 10:48:53.716 32329-32360/name.company.newapp E/GMPM: Uploading is not possible. App measurement disabled
11-14 10:48:53.936 32329-32329/name.company.newapp W/ActionBarDrawerToggle: DrawerToggle may not show up because NavigationIcon is not visible. You may need to call actionbar.setDisplayHomeAsUpEnabled(true);
11-14 10:48:54.086 32329-32329/name.company.newapp D/Activity: performCreate Call secproduct feature valuefalse
11-14 10:48:54.086 32329-32329/name.company.newapp D/Activity: performCreate Call debug elastic valuetrue
11-14 10:48:54.236 32329-32397/name.company.newapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
11-14 10:48:54.236 32329-32397/name.company.newapp I/System.out: (HTTPLog)-Static: isShipBuild true
11-14 10:48:54.236 32329-32397/name.company.newapp I/System.out: (HTTPLog)-Thread-46981-669037014: SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
11-14 10:48:54.236 32329-32397/name.company.newapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
11-14 10:48:54.256 32329-32397/name.company.newapp I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false
11-14 10:48:54.326 32329-32427/name.company.newapp D/OpenGLRenderer: Render dirty regions requested: true
11-14 10:48:54.456 32329-32427/name.company.newapp I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1_RB1.05.00.00.002.025_msm8974_LA.BF.1.1_RB1__release_AU ()
11-14 10:48:54.456 32329-32427/name.company.newapp I/Adreno-EGL: OpenGL ES Shader Compiler Version: E031.25.01.03
11-14 10:48:54.456 32329-32427/name.company.newapp I/Adreno-EGL: Build Date: 11/19/14 Wed
11-14 10:48:54.456 32329-32427/name.company.newapp I/Adreno-EGL: Local Branch: mybranch5813579
11-14 10:48:54.456 32329-32427/name.company.newapp I/Adreno-EGL: Remote Branch: quic/LA.BF.1.1_rb1.11
11-14 10:48:54.456 32329-32427/name.company.newapp I/Adreno-EGL: Local Patches: NONE
11-14 10:48:54.456 32329-32427/name.company.newapp I/Adreno-EGL: Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1_RB1.05.00.00.002.025 + 30e7589 +  NOTHING
11-14 10:48:54.456 32329-32427/name.company.newapp I/OpenGLRenderer: Initialized EGL, version 1.4
11-14 10:48:54.486 32329-32427/name.company.newapp I/OpenGLRenderer: HWUI protection enabled for context ,  &this =0xaf655060 ,&mEglDisplay = 1 , &mEglConfig = 8 
11-14 10:48:54.486 32329-32427/name.company.newapp D/OpenGLRenderer: Enabling debug mode 0
11-14 10:48:54.516 32329-32329/name.company.newapp E/RecyclerView: No adapter attached; skipping layout
11-14 10:48:54.656 32329-32329/name.company.newapp E/RecyclerView: No adapter attached; skipping layout
11-14 10:48:54.686 32329-32329/name.company.newapp I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@3fd3565e time:166096419
11-14 10:48:56.566 32329-32329/name.company.newapp D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-14 10:48:56.636 32329-32329/name.company.newapp D/AndroidRuntime: Shutting down VM
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime: FATAL EXCEPTION: main
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime: Process: name.company.newapp, PID: 32329
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.support.v7.widget.RecyclerView$LayoutManager.canScrollVertically()' on a null object reference
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.support.v7.widget.RecyclerView.computeVerticalScrollRange(RecyclerView.java:1654)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.onDrawScrollBars(View.java:13827)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.draw(View.java:16192)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:3097)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.updateDisplayListIfDirty(View.java:15109)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.getDisplayList(View.java:15132)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.draw(View.java:15907)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.drawChild(ViewGroup.java:3703)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1229)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3497)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.updateDisplayListIfDirty(View.java:15104)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.getDisplayList(View.java:15132)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3687)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3666)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.updateDisplayListIfDirty(View.java:15069)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.getDisplayList(View.java:15132)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3687)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3666)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.updateDisplayListIfDirty(View.java:15069)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.getDisplayList(View.java:15132)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3687)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3666)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.updateDisplayListIfDirty(View.java:15069)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.getDisplayList(View.java:15132)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3687)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3666)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.updateDisplayListIfDirty(View.java:15069)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.getDisplayList(View.java:15132)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3687)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3666)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.updateDisplayListIfDirty(View.java:15069)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.getDisplayList(View.java:15132)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3687)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3666)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.updateDisplayListIfDirty(View.java:15069)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.View.getDisplayList(View.java:15132)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:275)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:281)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:320)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewRootImpl.draw(ViewRootImpl.java:2751)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2584)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2176)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1191)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6642)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.Choreographer.doCallbacks(Choreographer.java:590)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.Choreographer.doFrame(Choreographer.java:560)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:145)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5938)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
11-14 10:48:56.636 32329-32329/name.company.newapp E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
11-14 10:49:09.356 32329-32428/name.company.newapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false

1 个答案:

答案 0 :(得分:-1)

mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setAdapter(mAdapter)

为我工作