reflect: call of reflect.Value.X on zero Value Go Origin: Application & API Last updated 4 Nov 2026

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.

Exact message you may see 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
Seen on: Go

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

  1. Check v.IsValid() and v.Kind() == reflect.Ptr && !v.IsNil()
  2. Pass a non-nil pointer to Unmarshal/Scan
  3. Validate field names

Detailed fix by platform

Go

  1. if !v.IsValid() { return errors.New("invalid value") }

How to diagnose

  1. Value — IsValid?
  2. Kind — Pointer nil?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

fatal error: stack overflow — Go: runtime: goroutine stack exceeds 1000000000-byte limit — fatal error: stack overflow (Go)fatal error: stack ov…invalid memory address or nil pointer dereference — Go: panic: runtime error: invalid memory address or nil pointer dereference (Go)invalid memory addres…json: cannot unmarshal string into Go struct field — Go: json: cannot unmarshal string into Go struct field User.age of type int (Go)json: cannot unmarsha…panic: assignment to entry in nil map — Go: panic: assignment to entry in nil map (Go)panic: assignment to …panic: interface conversion — Go: panic: interface conversion: interface {} is string, not int (Go)panic: interface conv…panic: runtime error: index out of range — Go: panic: runtime error: index out of range [3] with length 3 (Go)panic: runtime error:…panic: runtime error: integer divide by zero — Go: panic: runtime error: integer divide by zero (Go)panic: runtime error:…panic: slice bounds out of range — Go: panic: runtime error: slice bounds out of range [:5] with capacity 3 (Go)panic: slice bounds o…reflect: …

Explore the map of this error Full error map →

🧠 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.