DrKLO/Telegram · error · IllegalStateException
{positionDescription}: Class is not a LayoutManager {classNa
Error message
{positionDescription}: Class is not a LayoutManager {className} What it means
The class named by app:layoutManager loads and instantiates, but is not a subclass of RecyclerView.LayoutManager (the earlier asSubclass(LayoutManager.class) succeeded via the typed path, yet a ClassCastException surfaces during newInstance/setLayoutManager). RecyclerView reports 'Class is not a LayoutManager'.
Source
Thrown at TMessagesProj/src/main/java/androidx/recyclerview/widget/RecyclerView.java:883
+ ": Error creating LayoutManager " + className, e1);
}
}
constructor.setAccessible(true);
setLayoutManager(constructor.newInstance(constructorArgs));
} catch (ClassNotFoundException e) {
throw new IllegalStateException(attrs.getPositionDescription()
+ ": Unable to find LayoutManager " + className, e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(attrs.getPositionDescription()
+ ": Could not instantiate the LayoutManager: " + className, e);
} catch (InstantiationException e) {
throw new IllegalStateException(attrs.getPositionDescription()
+ ": Could not instantiate the LayoutManager: " + className, e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(attrs.getPositionDescription()
+ ": Cannot access non-public constructor " + className, e);
} catch (ClassCastException e) {
throw new IllegalStateException(attrs.getPositionDescription()
+ ": Class is not a LayoutManager " + className, e);
}
}
}
}
private String getFullClassName(Context context, String className) {
if (className.charAt(0) == '.') {
return context.getPackageName() + className;
}
if (className.contains(".")) {
return className;
}
return RecyclerView.class.getPackage().getName() + '.' + className;
}
private void initChildrenHelper() {
mChildHelper = new ChildHelper(new ChildHelper.Callback() {View on GitHub (pinned to 45ab8f4308)
Solutions
- Ensure app:layoutManager names a concrete subclass of RecyclerView.LayoutManager (LinearLayoutManager, GridLayoutManager, StaggeredGridLayoutManager, or your own subclass).
- Double-check the FQN against the actual class hierarchy.
- If you only need a different view type, that belongs on the item layout / Adapter, not layoutManager.
Example fix
<!-- before -->
<androidx.recyclerview.widget.RecyclerView
app:layoutManager="com.example.MyRecyclerAdapter"/>
<!-- after -->
<androidx.recyclerview.widget.RecyclerView
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/> Defensive patterns
Strategy: type-guard
Validate before calling
static void assertLayoutManager(Class<?> c) {
if (!RecyclerView.LayoutManager.class.isAssignableFrom(c)) {
throw new IllegalArgumentException(c.getName() + " is not a LayoutManager");
}
} Type guard
static boolean isLayoutManagerClass(Class<?> c) {
return RecyclerView.LayoutManager.class.isAssignableFrom(c);
} Try / catch
null
Prevention
- Cross-check the layoutManager class FQN against a LayoutManager subclass.
- Do not confuse Adapter/ViewHolder class names with LayoutManager.
- Add a lint/test that asserts every app:layoutManager resolves to a LayoutManager subclass.
When it happens
Trigger: app:layoutManager names a class that is NOT a LayoutManager subclass (e.g. a ViewHolder, an Adapter, a plain View). The asSubclass check passed via a different code shape but the assignment to setLayoutManager fails the cast.
Common situations: Confusing the layoutManager attribute with the view class itself. Pasting a class name from a different framework role (Adapter vs LayoutManager).
Related errors
- {positionDescription}: Error creating LayoutManager {classNa
- {positionDescription}: Unable to find LayoutManager {classNa
- {positionDescription}: Could not instantiate the LayoutManag
- {positionDescription}: Cannot access non-public constructor
- view is not a child, cannot hide {}
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/c9f8a05f0f61db73.
Report an issue: GitHub.