android - Null Pointer Exception in Layout Inflater of custom layout in for loop -


i using recyclerview in want inflate second layout using loop give null pointer exception in layoutinflater of second layout.

i made adapter class below

 public dataobjectholder(view itemview) {         super(itemview);         //label = (textview) itemview.findviewbyid(r.id.textview);         //datetime = (textview) itemview.findviewbyid(r.id.textview2);         log.i(log_tag, "adding listener");        //itemview.setonclicklistener(this);          main_layout = (linearlayout) itemview.findviewbyid(r.id.main_layout);      }   }  @override public dataobjectholder oncreateviewholder(viewgroup parent,                                            int viewtype) {     view view = layoutinflater.from(parent.getcontext())             .inflate(r.layout.services_layout, parent, false);         for(int i=0; i<=5 ; i++)         {             layoutinflater inflater = layoutinflater.from(context);             view inflatedlayout= inflater.inflate(r.layout.nested_list, null, false);             main_layout.addview(inflatedlayout);         }      dataobjectholder dataobjectholder = new dataobjectholder(view);     return dataobjectholder; } 

it give null pointer exception on line

layoutinflater inflater = layoutinflater.from(context);

services_layout xml layout is

 <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content">              <textview                 android:id="@+id/txt_intra"                 android:layout_width="wrap_content"                 android:layout_height="match_parent"                 android:layout_marginright="10dp"                 android:textcolor="#383838"                 android:textsize="15sp" />          </linearlayout>           <linearlayout             android:id="@+id/main_layout"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="vertical">          </linearlayout> 

nested_list xml layout is

 <linearlayout     android:layout_width="match_parent"     android:layout_height="wrap_content">      <textview../>      <textview       ../> </linearlayout> 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -