android - unable to get fragment context? showing unreachable code -
unable fragment context while running application,showing unreachable code. have created databasehelper parameterized constructor context.
public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment view view = inflater.inflate(r.layout.fragment_direct_search,container,false); try { mydbhelper.createdatabase(getactivity()); } catch (ioexception e) { e.printstacktrace(); }catch(sqlexception sqle){ throw sqle; } try { mydbhelper.opendatabase(); }catch(sqlexception sqle){ throw sqle; } toast.maketext(getactivity(), "successfully copied...", toast.length_short).show(); listview=(listview)view.findviewbyid(r.id.listview); populatelistview(); return view; } this databasehelper() constructor in databasehelper class :
public databasehelper(context context) { super(context, db_name, null, 1); this.mycontext = context; db_path = "/data/data/" + context.getpackagename() + "/" + "databases/"; } getting following error while running application unreachable code. error occuring @ following line :
mydbhelper.createdatabase(getactivity()); error : unreachable code
return inflater.inflate(r.layout.fragment_direct_search,container,false); is done quite in method, therefore nothing after executed. fix change to:
view view = inflater.inflate(r.layout.fragment_direct_search,container,false); and put in end of method;
return view; edit:
to listview can change
listview=(listview)listview.findviewbyid(r.id.listview); to
listview=(listview)view.findviewbyid(r.id.listview); and context pass getactivity() instead of this.
Comments
Post a Comment