글

10월, 2026의 게시물 표시

TypeError: 'NoneType' object is not subscriptable - 10 Causes and Fixes

이미지
TypeError: 'NoneType' object is not subscriptable means you used [...] on a value that is None . Python raises this the moment you write x[0] , x["key"] , or x[1:3] and x happens to be None - the subscript operator simply does not exist on the NoneType type. The traceback tells you where the subscript happened, not where the None came from. That gap is the whole debugging problem: the real bug is usually several lines (or several functions) earlier, at the point something returned None and you assumed it returned a dict, a list, or a string. This page lists the concrete ways a None gets into a subscript - functions with a missing return , mutating methods like sort() and append() , regex search() misses, dict.get() on an absent key, JSON null , DB queries with no rows - each with a reproduction, the fix, and a way to verify. If your case does not match any of them, work the diagnostic checklist instead. Error TypeError: 'NoneType' object i...

Error: A component is changing an uncontrolled input of type ... to be controlled. - 10 Causes and Fixes

이미지
React just logged Error: A component is changing an uncontrolled input of type ... to be controlled. in your console, and the input you were typing into probably still works - which is why this one is easy to ignore for weeks. It is not a crash; it is React telling you that a single <input> was mounted without a value prop (or with value={undefined} ) and then re-rendered with one. That switch matters because React manages the two kinds of inputs differently. An uncontrolled input keeps its text in the DOM node. A controlled input keeps it in your state and forces the DOM to match. Flipping between the two mid-life means React has to decide whose copy of the text wins, and the answer is not always the one you wanted - cursor jumps, wiped characters, and "my form resets when data loads" bugs all trace back here. This page covers the ten concrete ways a value prop goes from undefined to a string, each with a reproduction you can paste into a component, the lines ...

panic: runtime error: index out of range - 11 Causes and Fixes in Go

이미지
panic: runtime error: index out of range means you asked for an element at a position that does not exist, and Go killed the goroutine rather than hand you garbage. Modern Go appends the specifics, so you usually see something like panic: runtime error: index out of range [3] with length 3 or panic: runtime error: index out of range 0 with length 0 - and those two numbers are the whole diagnosis. The index is what your code asked for. The length is what the slice, array, or string actually had. If the index equals the length, you have an off-by-one in a loop bound. If the length is 0 , the collection was empty or nil and the real bug is upstream, in whatever was supposed to fill it. If the index is negative, you fed a not-found sentinel like -1 straight into a subscript. Below are 11 distinct causes, most common first, each with a reproduction you can paste into main.go and the fix that differs from it by the lines that matter. After that, a diagnostic checklist for the case tha...

java.lang.NullPointerException - 12 Causes and Fixes (Including Minecraft Crashes)

이미지
java.lang.NullPointerException means your code reached a reference that holds null and then used it as if it held an object. The JVM throws java.lang.NullPointerException at the exact moment of the dereference - a field read, a method call, an array index, or an unboxing - not where the null was created, which is why the stack trace line is often innocent and the real bug is three calls upstream. On JDK 15 and later the message does most of the work for you. Instead of a bare one-liner you get something like Cannot invoke "String.toUpperCase()" because "region" is null , which names both the failed operation and the null reference. If you are seeing a bare message, you are on an older JDK or the detail flag is off - step 1 of the checklist below fixes that. This page gives you the fastest fix first , then 12 distinct causes with a reproduction and a corrected version for each, a diagnostic checklist for cases that match none of them, and an explanation of why t...