{"record":{"id":"24e4c2dd55810a6d","repo":"NativeScript/NativeScript","slug":"element-cannot-be-null-or-undefinied-24e4c2","errorCode":null,"errorMessage":"element cannot be null or undefinied.","messagePattern":"element cannot be null or undefinied\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/ui/layouts/flexbox-layout/flexbox-layout-common.ts","lineNumber":139,"sourceCode":"\t}\n}\n\nexport type AlignSelf = 'auto' | AlignItems;\nexport namespace AlignSelf {\n\texport const AUTO = 'auto';\n\texport const FLEX_START = 'flex-start';\n\texport const FLEX_END = 'flex-end';\n\texport const CENTER = 'center';\n\texport const BASELINE = 'baseline';\n\texport const STRETCH = 'stretch';\n\n\texport const isValid = makeValidator<AlignSelf>(AUTO, FLEX_START, FLEX_END, CENTER, BASELINE, STRETCH);\n\texport const parse = makeParser<AlignSelf>(isValid);\n}\n\nfunction validateArgs(element: View): View {\n\tif (!element) {\n\t\tthrow new Error('element cannot be null or undefinied.');\n\t}\n\n\treturn element;\n}\n\n/**\n * A common base class for all cross platform flexbox layout implementations.\n */\n@CSSType('FlexboxLayout')\nexport abstract class FlexboxLayoutBase extends LayoutBase {\n\tget flexDirection(): FlexDirection {\n\t\treturn this.style.flexDirection;\n\t}\n\tset flexDirection(value: FlexDirection) {\n\t\tthis.style.flexDirection = value;\n\t}\n\n\tget flexWrap(): FlexWrap {","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/NativeScript/NativeScript/blob/6800aefa6511d23ddad8beb38ccc8541c5e91628/packages/core/ui/layouts/flexbox-layout/flexbox-layout-common.ts#L121-L157","documentation":"FlexboxLayout's static attached-property helpers (setOrder/getOrder, setFlexGrow/getFlexGrow, setFlexShrink/getFlexShrink) require a View instance. validateArgs throws when the element argument is null or undefined.","triggerScenarios":"FlexboxLayout.setOrder(null, 1), getFlexGrow(undefined), setFlexShrink(view-not-loaded, 0); passing result of a failed getViewById().","commonSituations":"Configuring flex children before they are added/looked up; variables cleared after view removal; copy-paste calling helpers with the wrong variable.","solutions":["Ensure a real View is passed to all six helpers","Check getViewById()/lookups for undefined before use","Guard calls with if (child)"],"exampleFix":"// before\nFlexboxLayout.setOrder(container.getViewById('a'), 2);\n// after\nconst a = container.getViewById('a');\nif (a) {\n  FlexboxLayout.setOrder(a, 2);\n}","handlingStrategy":"type-guard","validationCode":"const child = flexbox.getViewById('item');\nif (child != null) {\n  FlexboxLayout.setOrder(child, 1);\n  FlexboxLayout.setFlexGrow(child, 1);\n}","typeGuard":"function isNonNull<T>(v: T | null | undefined): v is T {\n  return v != null;\n}","tryCatchPattern":"try {\n  FlexboxLayout.setFlexGrow(child, 2);\n} catch (e) {\n  if (String(e.message).includes('element cannot be null')) {\n    // re-resolve or skip child\n  }\n}","preventionTips":["Null-check results of getViewById before attached-property calls","Set flex attached properties after children exist in the tree","Assert child presence in dev with console.assert(child != null)"],"tags":["null","argument-validation","flexboxlayout"],"backgroundTag":"null-or-undefined-argument","analyzedSha":"6800aefa6511d23ddad8beb38ccc8541c5e91628","analyzedAt":"2026-08-30T20:04:56.809Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}