PhillyTalon
PhillyTalon

Reputation: 33

Why is an error generated when I declare a nested static Fragment class as private?

I created an activity for my Android project and decided to change the access modifier for the nested Fragment class to "private", I figured that the outer Activity class is the only element of my program that needs to access this Fragment class. When I go to build in eclipse I receive the following error message "This Fragment class should be public ....", why is this error generated?

"`private static class PlaceholderFragment extends ListFragment {...."`

Upvotes: 3

Views: 271

Answers (1)

Thorn G
Thorn G

Reputation: 12766

Because the Android framework may need to invoke the no-arg constructor of your Fragment via reflection, which it can't do if the class is private.

Upvotes: 6

Related Questions