A
A
aiba08972019-06-18 10:02:15
go
aiba0897, 2019-06-18 10:02:15

How to solve runtime error: invalid memory address or nil pointer dereference?

Finish [GET] /admin/ Took 4364.66ms
http: panic serving 127.0.0.1:51374: runtime error: invalid memory address or nil pointer dereference
goroutine 8 [running]:
net/http.(*conn).serve.func1(0xc0003a0640)
        /usr/local/go/src/net/http/server.go:1769 +0x139
panic(0x17a8400, 0x1f30240)
        /usr/local/go/src/runtime/panic.go:522 +0x1b5
html/template.(*Template).escape(0x0, 0x0, 0x0)
        /usr/local/go/src/html/template/template.go:95 +0x2e
html/template.(*Template).Execute(0x0, 0x2744798, 0xc000316000, 0x1890600, 0xc000182000, 0x1, 0xc000194000)
        /usr/local/go/src/html/template/template.go:119 +0x2f
github.com/qor/admin.(*Context).Execute(0xc000182000, 0x189bc7f, 0x9, 0x0, 0x0)
        /Users/marsstudio/go/pkg/mod/github.com/qor/[email protected]/context.go:227 +0x22c
github.com/qor/admin.(*Controller).Dashboard(...)
        /Users/marsstudio/go/pkg/mod/github.com/qor/[email protected]/controller.go:28
github.com/qor/admin.(*Admin).NewServeMux.func2(0xc000182000, 0xc0002a4240)
        /Users/marsstudio/go/pkg/mod/github.com/qor/[email protected]/route.go:176 +0x202
github.com/qor/admin.Middleware.Next(...)
        /Users/marsstudio/go/pkg/mod/github.com/qor/[email protected]/route.go:37
github.com/qor/admin.(*Admin).NewServeMux.func1(0xc000182000, 0xc0002a4220)
        /Users/marsstudio/go/pkg/mod/github.com/qor/[email protected]/route.go:166 +0x119
github.com/qor/admin.Middleware.Next(...)
        /Users/marsstudio/go/pkg/mod/github.com/qor/[email protected]/route.go:37
github.com/qor/admin.Admin.registerCompositePrimaryKeyCallback.func1(0xc000182000, 0xc0004ea8c0)
        /Users/marsstudio/go/pkg/mod/github.com/qor/[email protected]/composite_primary_key_callback.go:27 +0x251
github.com/qor/admin.(*serveMux).ServeHTTP(0xc0000b3620, 0x2705c18, 0xc000316000, 0xc00013a000)
        /Users/marsstudio/go/pkg/mod/github.com/qor/[email protected]/route.go:267 +0x52c
net/http.(*ServeMux).ServeHTTP(0xc0000a7980, 0x2705c18, 0xc000316000, 0xc00013a000)
        /usr/local/go/src/net/http/server.go:2376 +0x1d6
github.com/gin-gonic/gin.WrapH.func1(0xc000316000)
        /Users/marsstudio/go/pkg/mod/github.com/gin-gonic/[email protected]/utils.go:48 +0x90
github.com/gin-gonic/gin.(*Context).Next(0xc000316000)
        /Users/marsstudio/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:108 +0x43
github.com/gin-contrib/sessions.Sessions.func1(0xc000316000)
        /Users/marsstudio/go/pkg/mod/github.com/gin-contrib/[email protected]/sessions.go:65 +0x1a0
github.com/gin-gonic/gin.(*Context).Next(0xc000316000)
        /Users/marsstudio/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:108 +0x43
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc0001606c0, 0xc000316000)
        /Users/marsstudio/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:361 +0x597
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc0001606c0, 0x19fe240, 0xc000512000, 0xc00013a000)
        /Users/marsstudio/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:326 +0x134
net/http.serverHandler.ServeHTTP(0xc0000d0410, 0x19fe240, 0xc000512000, 0xc00013a000)
        /usr/local/go/src/net/http/server.go:2775 +0xa8
net/http.(*conn).serve(0xc0003a0640, 0x1a00540, 0xc000066080)
        /usr/local/go/src/net/http/server.go:1879 +0x851
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2885 +0x2f4

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Papa, 2019-06-18
Stifflera @PapaStifflera

Run a debugger, locate the problem, fix the problem.

A
Alexander Pavlyuk, 2019-06-18
@pav5000

I can’t say for sure without the code, but I know that in the template you are trying to access the field of the object, which is nil.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question