Calling Fragment constructor caused an exception. Navigation Architecture Component

I had the similar issue because I had val in MyBaseFragment

protected abstract val gpsMsg: String

which I was overiding this way in other Fragment before fragment attached to context.

override val gpsMsg: String = getString(R.string.gps_not_enabled)

So the underlying error was because context was null and getString uses getResources() which returns requireContext().getResources(). And in the requireContext() source code error will be thrown.

public final Context requireContext() {
    Context context = getContext();
    if (context == null) {
        throw new IllegalStateException("Fragment " + this + " not attached to a context.");
    }
    return context;
}

So the error thrown causes fragment not to be instantiated. So I would advice being careful with context thing when override.