DrKLO/Telegram · error · IllegalStateException
{positionDescription}: Unable to find LayoutManager {classNa
Error message
{positionDescription}: Unable to find LayoutManager {className} What it means
During XML inflation of RecyclerView, the app:layoutManager class name is resolved by Class.forName. ClassNotFoundException produces 'Unable to find LayoutManager <className>'. The class string in the attribute could not be loaded at runtime.
Source
Thrown at TMessagesProj/src/main/java/androidx/recyclerview/widget/RecyclerView.java:871
Constructor<? extends LayoutManager> constructor;
Object[] constructorArgs = null;
try {
constructor = layoutManagerClass
.getConstructor(LAYOUT_MANAGER_CONSTRUCTOR_SIGNATURE);
constructorArgs = new Object[]{context, attrs, defStyleAttr, defStyleRes};
} catch (NoSuchMethodException e) {
try {
constructor = layoutManagerClass.getConstructor();
} catch (NoSuchMethodException e1) {
e1.initCause(e);
throw new IllegalStateException(attrs.getPositionDescription()
+ ": 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);
}
}
}
}
View on GitHub (pinned to 45ab8f4308)
Solutions
- Verify the fully-qualified class name in app:layoutManager matches a real class on the runtime classpath.
- If using '.'-relative names, confirm applicationId matches the package containing the class.
- Add a ProGuard -keep rule for any LayoutManager referenced from XML so obfuscation does not rename it.
Example fix
<!-- before -->
<androidx.recyclerview.widget.RecyclerView
app:layoutManager="androidx.Recyclerview.widget.GridLayoutManager"/>
<!-- after -->
<androidx.recyclerview.widget.RecyclerView
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"/> Defensive patterns
Strategy: validation
Validate before calling
static Class<?> resolveLayoutManagerClass(Context ctx, String name) throws ClassNotFoundException {
String fqn = name.charAt(0) == '.' ? ctx.getPackageName() + name : name;
return Class.forName(fqn, false, ctx.getClassLoader());
} Type guard
null
Try / catch
try {
Class<?> c = Class.forName(fqn);
if (!RecyclerView.LayoutManager.class.isAssignableFrom(c)) throw new IllegalStateException();
} catch (ClassNotFoundException e) {
// log and fall back to a programmatic LayoutManager
recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
} Prevention
- Pin layoutManager class names against real classes via an inflation test.
- Add ProGuard -keep rules for any LayoutManager referenced from XML.
- Prefer programmatic setLayoutManager when the class is obfuscated.
When it happens
Trigger: app:layoutManager points to a class that does not exist, is misspelled, uses a wrong package, or has been renamed/removed by ProGuard/R8 obfuscation. A relative name (leading '.') is prefixed with the app package — a wrong package base yields a missing class.
Common situations: Typo in the class FQN in XML. LayoutManager lives in a library that is not on the classpath at runtime (e.g. dynamic-feature module). Obfuscation renamed the class so the XML string no longer matches. Wrong applicationId makes the '.'-relative resolution resolve to a non-existent package.
Related errors
- {positionDescription}: Error creating LayoutManager {classNa
- {positionDescription}: Could not instantiate the LayoutManag
- {positionDescription}: Cannot access non-public constructor
- {positionDescription}: Class is not a LayoutManager {classNa
- view is not a child, cannot hide {}
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/a0df8cd20e249ec2.
Report an issue: GitHub.