Go: panic: reflect: call of reflect.Value.Elem on zero Value
Reflection code operated on an invalid (zero) reflect.Value, often derived from a nil pointer or a missing struct field.
reflect: call of reflect.Value.Elem on zero Valuereflect: call of reflect.Value.Interface on zero Valuepanic: reflect: call of reflect.Value.Field on ptr Valuereflect: call of reflect.Value.Type on zero Valuereflect.Value.SetString using unaddressable value Meaning
reflect.ValueOf(nil) and FieldByName for a nonexistent field return an invalid Value. Check v.IsValid() and v.Kind() before calling methods. JSON/validation libraries trigger this when given nil interfaces.
Common causes
- reflect.ValueOf(nil)
- FieldByName for a missing field
- Elem() on a nil pointer
- Interface holding nil passed to a library
- Wrong struct tag lookup
⚡ Quick fix
- Check
v.IsValid()andv.Kind() == reflect.Ptr && !v.IsNil() - Pass a non-nil pointer to Unmarshal/Scan
- Validate field names
Detailed fix by platform
Go
if !v.IsValid() { return errors.New("invalid value") }
How to diagnose
- Value — IsValid?
- Kind — Pointer nil?
- Field — Exists?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- fatal error: stack overflow Go: runtime: goroutine stack exceeds 1000000000-byte limit — fatal error: stack overflow
- invalid memory address or nil pointer dereference Go: panic: runtime error: invalid memory address or nil pointer dereference
- json: cannot unmarshal string into Go struct field Go: json: cannot unmarshal string into Go struct field User.age of type int
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026