java - Why am I getting an error when making a FragmentPageAdapter? -
im working through tutorial can slide through tabs in view. requires me make subclass of fragmentpageadapter - in case:
public class pageradapter extends fragmentpageradapter { ... } i have implemented of abstract methods reason getting following error: there no default constructor available in 'android.support.v4.app.fragmentpageadapter'
does know how can fix this? highly appreciated.
if don't specify constructor in class pageradapter , default constructor no-args used, looks parent class no-args constructor, equivalent to.
public pageradapter(){ super(); // looks constructor public fragmentpageradapter (){} } in parent class fragmentpageradapter there below constructor defined
public fragmentpageradapter (fragmentmanager fm) now rule in java is, once constructor arguments defined , default no-args constructor not available unless explicitly define it. here public fragmentpageradapter (){} not there. that's why super() call fails find no-args default constructor , error.
to handle this, in class pageradapter need have constructor invoke correct super class constructor
public pageradapter(fragmentmanager fm){ super(fm); }
Comments
Post a Comment