遇到运行时错误:无效的内存地址或无指针取消引用

时间:2016-07-13 17:00:31

标签: memory go nullpointerexception runtime-error

我试图关注官方网站上的tutorial。在Using net/http to serve wiki pages部分,我直接在Click here to view the code we've written so far复制代码,但我无法访问http://localhost:8080/view/test并获得以下内容。

enter image description here

由于我使用LiteIDE,我可以看到以下内容。

Killing current process...
Error: process crashed or was terminated while running.
F:/Go/bin/go.exe build -i [E:/Users/User/Desktop/New folder (36)/codespace_v2.6/codespace/dev/server_side/golang/go_codespace_v2.0/server]
Success: process exited with code 0.
E:/Users/User/Desktop/New folder (36)/codespace_v2.6/codespace/dev/server_side/golang/go_codespace_v2.0/server/server.exe  [E:/Users/User/Desktop/New folder (36)/codespace_v2.6/codespace/dev/server_side/golang/go_codespace_v2.0/server]
2016/07/14 00:49:14 http: panic serving [::1]:65281: runtime error: invalid memory address or nil pointer dereference
goroutine 5 [running]:
net/http.(*conn).serve.func1(0xc08200a300)
    F:/Go/src/net/http/server.go:1389 +0xc8
panic(0x711700, 0xc0820060f0)
    F:/Go/src/runtime/panic.go:443 +0x4f7
main.viewHandler(0xea0058, 0xc0820be000, 0xc0820a81c0)
    E:/Users/User/Desktop/New folder (36)/codespace_v2.6/codespace/dev/server_side/golang/go_codespace_v2.0/server/main.go:35 +0x241
net/http.HandlerFunc.ServeHTTP(0x80b890, 0xea0058, 0xc0820be000, 0xc0820a81c0)
    F:/Go/src/net/http/server.go:1618 +0x41
net/http.(*ServeMux).ServeHTTP(0xc082050870, 0xea0058, 0xc0820be000, 0xc0820a81c0)
    F:/Go/src/net/http/server.go:1910 +0x184
net/http.serverHandler.ServeHTTP(0xc08200a280, 0xea0058, 0xc0820be000, 0xc0820a81c0)
    F:/Go/src/net/http/server.go:2081 +0x1a5
net/http.(*conn).serve(0xc08200a300)
    F:/Go/src/net/http/server.go:1472 +0xf35
created by net/http.(*Server).Serve
    F:/Go/src/net/http/server.go:2137 +0x455
2016/07/14 00:49:14 http: panic serving [::1]:65282: runtime error: invalid memory address or nil pointer dereference
goroutine 17 [running]:
net/http.(*conn).serve.func1(0xc0820ae100)
    F:/Go/src/net/http/server.go:1389 +0xc8
panic(0x711700, 0xc0820060f0)
    F:/Go/src/runtime/panic.go:443 +0x4f7
main.viewHandler(0xea0058, 0xc0820be1a0, 0xc0820e20e0)
    E:/Users/User/Desktop/New folder (36)/codespace_v2.6/codespace/dev/server_side/golang/go_codespace_v2.0/server/main.go:35 +0x241
net/http.HandlerFunc.ServeHTTP(0x80b890, 0xea0058, 0xc0820be1a0, 0xc0820e20e0)
    F:/Go/src/net/http/server.go:1618 +0x41
net/http.(*ServeMux).ServeHTTP(0xc082050870, 0xea0058, 0xc0820be1a0, 0xc0820e20e0)
    F:/Go/src/net/http/server.go:1910 +0x184
net/http.serverHandler.ServeHTTP(0xc08200a280, 0xea0058, 0xc0820be1a0, 0xc0820e20e0)
    F:/Go/src/net/http/server.go:2081 +0x1a5
net/http.(*conn).serve(0xc0820ae100)
    F:/Go/src/net/http/server.go:1472 +0xf35
created by net/http.(*Server).Serve
    F:/Go/src/net/http/server.go:2137 +0x455
2016/07/14 00:50:30 http: panic serving [::1]:65288: runtime error: invalid memory address or nil pointer dereference
goroutine 6 [running]:
net/http.(*conn).serve.func1(0xc08200a380)
    F:/Go/src/net/http/server.go:1389 +0xc8
panic(0x711700, 0xc0820060f0)
    F:/Go/src/runtime/panic.go:443 +0x4f7
main.viewHandler(0xea0058, 0xc0820be270, 0xc0820a8380)
    E:/Users/User/Desktop/New folder (36)/codespace_v2.6/codespace/dev/server_side/golang/go_codespace_v2.0/server/main.go:35 +0x241
net/http.HandlerFunc.ServeHTTP(0x80b890, 0xea0058, 0xc0820be270, 0xc0820a8380)
    F:/Go/src/net/http/server.go:1618 +0x41
net/http.(*ServeMux).ServeHTTP(0xc082050870, 0xea0058, 0xc0820be270, 0xc0820a8380)
    F:/Go/src/net/http/server.go:1910 +0x184
net/http.serverHandler.ServeHTTP(0xc08200a280, 0xea0058, 0xc0820be270, 0xc0820a8380)
    F:/Go/src/net/http/server.go:2081 +0x1a5
net/http.(*conn).serve(0xc08200a380)
    F:/Go/src/net/http/server.go:1472 +0xf35
created by net/http.(*Server).Serve
    F:/Go/src/net/http/server.go:2137 +0x455
2016/07/14 00:50:30 http: panic serving [::1]:65289: runtime error: invalid memory address or nil pointer dereference
goroutine 18 [running]:
net/http.(*conn).serve.func1(0xc0820ae280)
    F:/Go/src/net/http/server.go:1389 +0xc8
panic(0x711700, 0xc0820060f0)
    F:/Go/src/runtime/panic.go:443 +0x4f7
main.viewHandler(0xea0058, 0xc0820be340, 0xc0820e22a0)
    E:/Users/User/Desktop/New folder (36)/codespace_v2.6/codespace/dev/server_side/golang/go_codespace_v2.0/server/main.go:35 +0x241
net/http.HandlerFunc.ServeHTTP(0x80b890, 0xea0058, 0xc0820be340, 0xc0820e22a0)
    F:/Go/src/net/http/server.go:1618 +0x41
net/http.(*ServeMux).ServeHTTP(0xc082050870, 0xea0058, 0xc0820be340, 0xc0820e22a0)
    F:/Go/src/net/http/server.go:1910 +0x184
net/http.serverHandler.ServeHTTP(0xc08200a280, 0xea0058, 0xc0820be340, 0xc0820e22a0)
    F:/Go/src/net/http/server.go:2081 +0x1a5
net/http.(*conn).serve(0xc0820ae280)
    F:/Go/src/net/http/server.go:1472 +0xf35
created by net/http.(*Server).Serve
    F:/Go/src/net/http/server.go:2137 +0x455

我曾尝试使用CMD来构建go程序,但我仍然得到相同的结果。它一直在说invalid memory address or nil pointer dereference。如何解决这个问题?

0 个答案:

没有答案