I have a non-public final class that looks like the following:
final class FragmentManagerImpl {
...
}
Note that it is not public and it has no declared constructors.
I would like to instantiate an instance of this class using reflection. However, both of the following code snippets result in IllegalAccessExceptions:
// BUG IllegalAccessException on calling newInstance
final Class c = Class.forName("android.support.v4.app.FragmentManagerImpl");
c.newInstance();
// BUG IllegalAccessException on calling newInstance
final Class c = Class.forName("android.support.v4.app.FragmentManagerImpl");
final Constructor constructor = c.getDeclaredConstructor();
constructor.setAccessible(true);
constructor.newInstance();
What is the correct way to instantiate this class from a package that is not android.support.v4.app?
Hm, it appears to have been user error. Using the constructor method outlined in the question does seem to have worked properly.