Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make sure class name exists, is public, and has an empty constructor for public fragment with class name and empty constructor

I've just got a crash report from one of the users with the following error trace :

Unable to instantiate fragment packageName.Wizard$WizardFirstPage: make sure class name exists, is public, and has an empty constructor that is public   

Here are the classes declarations :

public class Wizard extends Other

public abstract class Other extends BaseActivity

public abstract class BaseActivity extends ActionBarActivity

All classes are public, named and doesn't have user defined constructor.

As for the fragment WizardFirstPage : (defined in Wizard)

public class WizardFirstPage extends Fragment

No user defined constructor either.

What am I missing ?

like image 531
SagiLow Avatar asked Feb 22 '15 18:02

SagiLow


1 Answers

public class WizardFirstPage extends Fragment

That is an inner class of packageName.Wizard. That will only work if the class is declared as static, as indicated by Blackbelt:

public static class WizardFirstPage extends Fragment

When the Wizard activity undergoes a configuration change, or is re-created after process termination, Android is going to try to create an instance of Wizard$WizardFirstPage. With your current approach, Android cannot do this, as only instances of Wizard can create instances of Wizard$WizardFirstPage. Changing WizardFirstPage to be static will fix this.

like image 175
CommonsWare Avatar answered Nov 14 '22 23:11

CommonsWare