Java – Why does I get an error when I declare a nested static fragment class as private?

Why does I get an error when I declare a nested static fragment class as private?… here is a solution to the problem.

Why does I get an error 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 of the nested Fragment class to “private”, and I consider the outer Activity class to be the only element in my program that needs access to that Fragment class. When I build in eclipse, I get the following error message “This Fragment class should be public….”, why is this error generated?

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

Solution

Because the Android framework may need to call Fragment’s parameterless constructor through reflection, it cannot do so if the class is private.

Related Problems and Solutions