Go error: unexpected Nul in input

Viewed 8097

I just installed the go.msi in C:/Go. And I set my Path(C:\Go\bin) and GOPATH(E:\code\go).But when I try to run "go run test.go" I get the following error: test.go:2:8: read C:\Go\src\fmt\export_test.go: unexpected NUL in input package main imports runtime: read C:\Go\src\runtime\export_unix_test.go: unexpected NUL in input
I can not open these files. The code i have is:

    package main

    import "fmt"

    func main()  {
        fmt.Println("Something")
    }

The path of the test.go file is E:\code\go\test.go When i run go env i get:

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\code\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config

the output of go version is: go version go1.9.2 windows/amd64

4 Answers

You are missing some things in your GOPATH. You need a folder structure like the following:

E:\code\go\src\{repository}\{package}\gofile.go

So for this, you could have it be:

E:\code\go\src\local-only\testing\test.go

For what it's worth, I just ran into this issue and solved it by running chkdsk /f from cmd.exe with administrative rights. (The command should be run against the drive Go is installed)

Somewhere on the web I read "The problem is that somewhere in your 'main.go' is a ASCII NULL character." To get past it:

  1. Copy all the code from 'main.go' into Notepad and save it
  2. Delete 'main.go'
  3. Create blank 'main.go'
  4. Paste code from Notepad into 'main.go'
  5. Run: go run . => Success
Related