Fragment Replace null pointer exception -


i trying replace fragment inside onitemclick of list view , want send selected item name list fragment fragment showing null pointer exception

@override public void onitemclick(adapterview arg0, view view, int position, long id) {

try     {         log.e("----- inside onitemclick -----", cityselected);          mapvisiblefragment newfragment = new mapvisiblefragment();         bundle args = new bundle();         args.putstring("cityname", cityselected);         newfragment.setarguments(args);         ((basecontainerfragment) getparentfragment()).replacefragment(                 newfragment, true);      } catch (exception e)     {         e.printstacktrace();     }  } 

but same concept working inside button click below one

 try   {      listfragmentfromdbrecords2 newfragment = new listfragmentfromdbrecords2();      bundle args = new bundle();      args.putstringarraylist("names", alldata);      newfragment.setarguments(args);      ((basecontainerfragment) getparentfragment()).replacefragment(       newfragment, true);       log.d("--->>>>", alldata.tostring());      }   catch (exception e)      {      e.printstacktrace();     } 

based on comment

((basecontainerfragment) getparentfragment()) 

is null you. check why getparentfragment() method returns null.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -