Throwing error when RecyclerView is added to xml layout file in Android -


i developing android application. trying use recyclerview in application. added recyclerxml layout file. when run app, throwing error. please see scenario below.

this main_activity xml

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.coordinatorlayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"     android:layout_height="match_parent" android:fitssystemwindows="true"     tools:context=".mainactivity">      <android.support.design.widget.appbarlayout         android:id="@+id/htab_appbar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:fitssystemwindows="true"         android:theme="@style/themeoverlay.appcompat.dark.actionbar">         <android.support.design.widget.collapsingtoolbarlayout             android:id="@+id/htab_collapse_toolbar"             android:layout_width="match_parent"             android:layout_height="@dimen/main_activity_parallax_initial_height"             android:fitssystemwindows="true"             app:contentscrim="?attr/colorprimary"             app:layout_scrollflags="scroll|exituntilcollapsed">             <relativelayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content">                 <imageview                     android:id="@+id/htab_header"                     android:layout_width="match_parent"                     android:layout_height="match_parent"                     android:background="@drawable/apple"                     android:fitssystemwindows="true"                     android:scaletype="centercrop"                     app:layout_collapsemode="parallax" />                 <textview                     android:layout_centerinparent="true"                     android:text="hello"                     android:textsize="20dp"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content" />             </relativelayout>             <android.support.v7.widget.toolbar                 android:id="@+id/htab_toolbar"                 android:layout_width="match_parent"                 android:layout_height="@dimen/main_activity_toolbar_height"                 android:gravity="top"                 android:minheight="?attr/actionbarsize"                 app:layout_collapsemode="pin"                 app:popuptheme="@style/themeoverlay.appcompat.light"                 app:titlemargintop="13dp" />           <!--  <android.support.design.widget.tablayout                 android:id="@+id/htab_tabs"                 android:layout_width="match_parent"                 android:layout_height="?attr/actionbarsize"                 android:layout_gravity="bottom"                 app:tabindicatorcolor="@android:color/white" />-->         </android.support.design.widget.collapsingtoolbarlayout>     </android.support.design.widget.appbarlayout>     <framelayout         android:id="@+id/default_content_container"         android:layout_width="match_parent"         android:layout_height="wrap_content"></framelayout> </android.support.design.widget.coordinatorlayout> 

then set content of default_content_container fragment.

this xml of fragment recycler view

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="match_parent"     android:layout_height="match_parent">     <android.support.v7.widget.recyclerview         android:id="@+id/dc_rv_destination"         android:scrollbars="vertical"         android:layout_width="match_parent"         android:layout_height="wrap_content"/> </linearlayout> 

i did not initialize , nothing in fragment.

but when run, giving me error.

05-28 14:42:15.956 8654-8654/com.deltatripagent.deltatripagent w/egl_genymotion: eglsurfaceattrib not implemented 05-28 14:42:15.956 8654-8654/com.deltatripagent.deltatripagent e/openglrenderer: getting max_texture_size gradiencache 05-28 14:42:15.956 8654-8654/com.deltatripagent.deltatripagent e/openglrenderer: getting max_texture_size caches::initconstraints() 05-28 14:42:15.960 8654-8654/com.deltatripagent.deltatripagent d/openglrenderer: enabling debug mode 0 05-28 14:42:15.960 8654-8654/com.deltatripagent.deltatripagent e/recyclerview: no adapter attached; skipping layout 05-28 14:42:15.964 8654-8654/com.deltatripagent.deltatripagent d/androidruntime: shutting down vm 05-28 14:42:15.964 8654-8654/com.deltatripagent.deltatripagent w/dalvikvm: threadid=1: thread exiting uncaught exception (group=0xa4bc9648) 05-28 14:42:15.964 8654-8654/com.deltatripagent.deltatripagent w/viewrootimpl: dropping event due no window focus: keyevent { action=action_down, keycode=keycode_alt_right, scancode=100, metastate=meta_alt_on|meta_alt_right_on, flags=0x8, repeatcount=25349, eventtime=1585081, downtime=277306, deviceid=1, source=0x301 } 05-28 14:42:15.964 8654-8654/com.deltatripagent.deltatripagent w/viewrootimpl: dropping event due no window focus: keyevent { action=action_down, keycode=keycode_alt_right, scancode=100, metastate=meta_alt_on|meta_alt_right_on, flags=0x8, repeatcount=25350, eventtime=1585450, downtime=277306, deviceid=1, source=0x301 } 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime: fatal exception: main 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime: java.lang.nullpointerexception 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.support.v7.widget.recyclerview.computeverticalscrollrange(recyclerview.java:1654) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.ondrawscrollbars(view.java:11596) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.draw(view.java:13950) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.support.v7.widget.recyclerview.draw(recyclerview.java:3097) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12838) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12880) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.draw(view.java:13657) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.drawchild(viewgroup.java:3086) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.dispatchdraw(viewgroup.java:2923) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12833) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12880) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.draw(view.java:13657) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.drawchild(viewgroup.java:3086) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.dispatchdraw(viewgroup.java:2923) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12833) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12880) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.draw(view.java:13657) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.drawchild(viewgroup.java:3086) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.support.design.widget.coordinatorlayout.drawchild(coordinatorlayout.java:1077) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.dispatchdraw(viewgroup.java:2923) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12833) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12880) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.draw(view.java:13657) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.drawchild(viewgroup.java:3086) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.dispatchdraw(viewgroup.java:2923) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.draw(view.java:13947) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.widget.framelayout.draw(framelayout.java:467) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12838) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12880) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.draw(view.java:13657) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.drawchild(viewgroup.java:3086) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.dispatchdraw(viewgroup.java:2923) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12833) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12880) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.draw(view.java:13657) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.drawchild(viewgroup.java:3086) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.dispatchdraw(viewgroup.java:2923) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12833) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12880) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.draw(view.java:13657) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.drawchild(viewgroup.java:3086) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.dispatchdraw(viewgroup.java:2923) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12833) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12880) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.draw(view.java:13657) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.drawchild(viewgroup.java:3086) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewgroup.dispatchdraw(viewgroup.java:2923) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.draw(view.java:13947) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.widget.framelayout.draw(framelayout.java:467) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ com.android.internal.policy.impl.phonewindow$decorview.draw(phonewindow.java:2224) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12838) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.view.getdisplaylist(view.java:12880) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.hardwarerenderer$glrenderer.builddisplaylist(hardwarerenderer.java:1411) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.hardwarerenderer$glrenderer.draw(hardwarerenderer.java:1359) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewrootimpl.draw(viewrootimpl.java:2367) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewrootimpl.performdraw(viewrootimpl.java:2239) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1872) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1004) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5481) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.choreographer$callbackrecord.run(choreographer.java:749) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.choreographer.docallbacks(choreographer.java:562) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.choreographer.doframe(choreographer.java:532) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:735) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.os.handler.handlecallback(handler.java:730) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.os.handler.dispatchmessage(handler.java:92) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.os.looper.loop(looper.java:137) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ android.app.activitythread.main(activitythread.java:5103) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:     @ java.lang.reflect.method.invokenative(native method) 05-28 14:42:15.968 8654-8654/com.deltatripagent.deltatripagent e/androidruntime:    @ java.la 

so please why cannot add recycler view? when add list view instead, can run app. please how can fix that? please me.

that happens because "did not initialize , nothing in fragment."

recyclerview must be initialised view layoutmanager after being inflated.

that happens because lot of layout calculation recycleview happens in layoutmanager.

that said, simple fix, after inflating fragment layout, during fragment oncreateview add layout manager via:

recycler.setlayoutmanager( /* add here layout manager of choice */ );  

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -