yuliskov/SmartTube · error · IllegalStateException
Can't create root of SurfacePlaybackFragment
Error message
Can't create root of SurfacePlaybackFragment
What it means
SurfacePlaybackFragment.onCreateView takes super.onCreateView(...) (the leanback PlaybackSupportFragment view inflation) and casts it to ViewGroup; if the base returns null it throws IllegalStateException('Can't create root of SurfacePlaybackFragment') to fail fast before root.findViewById(surface_root/leanback_subtitles) would NPE. A null super view means the base playback fragment's layout never inflated.
Source
Thrown at smarttubetv/src/main/java/com/liskovsoft/smartyoutubetv2/tv/ui/playback/mod/surface/SurfacePlaybackFragment.java:40
* Subclass of {@link PlaybackSupportFragment} that is responsible for providing a {@link SurfaceView}
* and rendering video.
*/
public class SurfacePlaybackFragment extends PlaybackSupportFragment {
private SurfaceWrapper mVideoSurfaceWrapper;
private AspectRatioFrameLayout mVideoSurfaceRoot;
private SubtitleView mLeanbackSubtitles;
private int mSubtitlesPadding;
private int mBackgroundResId;
private float mAspectRatio;
private float mPixelRatio = 1.0f;
private float mVideoAspectRatio;
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) super.onCreateView(inflater, container, savedInstanceState);
if (root == null) {
throw new IllegalStateException("Can't create root of SurfacePlaybackFragment");
}
mVideoSurfaceWrapper = (PlayerTweaksData.instance(getContext()).isTextureViewEnabled() ||
PlayerData.instance(getContext()).getRotationAngle() != 0) ?
new TextureViewWrapper(getContext(), root) : new SurfaceViewWrapper(getContext(), root);
mVideoSurfaceRoot = root.findViewById(com.liskovsoft.smartyoutubetv2.tv.R.id.surface_root);
mVideoSurfaceRoot.addView(mVideoSurfaceWrapper.getSurfaceView(), 0);
mVideoSurfaceRoot.setAspectRatioListener((targetAspectRatio, naturalAspectRatio, aspectRatioMismatch) -> scaleIfNeeded());
mLeanbackSubtitles = root.findViewById(com.liskovsoft.smartyoutubetv2.tv.R.id.leanback_subtitles);
mSubtitlesPadding = mLeanbackSubtitles.getPaddingLeft();
setBackgroundType(PlaybackSupportFragment.BG_LIGHT);
return root;
}
/**
* Adds {@link SurfaceHolder.Callback} to {@link SurfaceView}.
*/
public void setSurfaceHolderCallback(SurfaceHolder.Callback callback) {
if (mVideoSurfaceWrapper != null) {View on GitHub (pinned to 3de8d90593)
Solutions
- Check every intermediate override of onCreateView in your subclass chain — each must return the inflated view, never null.
- Align/pin the androidx.leanback dependency to a version compatible with this code (the base is expected to inflate a non-null video fragment layout).
- Verify the layout actually inflated (no silently swallowed InflateException) by logging super.onCreateView's result before the cast.
- If you maintain the code, replace the throw with a fallback inflation of a layout containing surface_root and leanback_subtitles.
Defensive patterns
Strategy: validation
Validate before calling
// in your subclass chain, make sure onCreateView never returns null
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = super.onCreateView(inflater, container, savedInstanceState);
if (root == null) {
// base failed to inflate — provide a layout with surface_root + leanback_subtitles
root = inflater.inflate(R.layout.surface_playback_fragment, container, false);
}
return root;
} Prevention
- Any override of onCreateView between your fragment and the leanback base must return the inflated view.
- Pin androidx.leanback to a version this code was built against; retest playback after upgrades.
- Confirm the expected ids (surface_root, leanback_subtitles) exist in the inflated layout.
When it happens
Trigger: The androidx.leanback base fragment's onCreateView returning null — typically a leanback version change in layout inflation, a subclass between SurfacePlaybackFragment and the base overriding onCreateView and returning null, or inflation failing silently on a null container during certain restore paths.
Common situations: Upgrading androidx.leanback to a version where PlaybackSupportFragment/VideoSupportFragment view creation changed; mod layers or forks overriding onCreateView without returning the inflated root; layouts missing the ids the code then uses (surface_root, leanback_subtitles).
Related errors
- VideoGridFragment doesn't attached to the activity
- Can't create PlaybackFragment: the context is null
- Invalid row %s
- Can't create SearchTagsFragment: the context is null
- You must pass either Activity, Fragment or SupportFragment
AI-assisted analysis of yuliskov/SmartTube@3de8d90593 (2026-08-22).
Data as JSON: /api/errors/70b3e8b57dcea0c9.
Report an issue: GitHub.