I have a Fragment with a constructor that takes multiple arguments. My app worked fine during development, but in production my users sometimes see this crash:

android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment 
make sure class name exists, is public, and has an empty constructor that is public

I could make an empty constructor as this error message suggests, but that doesn’t make sense to me since then I would have to call a separate method to finish setting up the Fragment.

I’m curious as to why this crash only happens occasionally. Maybe I’m using the ViewPager incorrectly? I instantiate all the Fragments myself and save them in a list inside the Activity. I don’t use FragmentManager transactions, since the ViewPager examples I have seen did not require it and everything seemed to be working during development.

5 Answers
5

Leave a Reply

Your email address will not be published. Required fields are marked *