简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM