Make sure that the class name exists, is public, and has an empty constructor for the public fragment with the class name and empty constructor

I just received an accident message 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 class declarations:

public class Wizard extends Other

public abstract class Other extends BaseActivity

public abstract class BaseActivity extends ActionBarActivity

All classes are publicly accessible, named, and do not have a user-defined constructor.

Regarding the WizardFirstPage : (defined in the Wizard )

public class WizardFirstPage extends Fragment

No custom constructor.

What am I missing?

+5
source share
1 answer
 public class WizardFirstPage extends Fragment 

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

 public static class WizardFirstPage extends Fragment 

When the Wizard activity undergoes a configuration change or is recreated after the process is complete, Android will try to instantiate the Wizard$WizardFirstPage . With your current approach, Android cannot do this, since only Wizard instances can create Wizard$WizardFirstPage . Changing WizardFirstPage to static will be fixed.

+9
source

Source: https://habr.com/ru/post/1213924/


All Articles