草庐IT

about_nil

全部标签

pointers - panic : runtime error: invalid memory address or nil pointer dereference

我目前正在使用Go的Soundcloud包装器,我想打印用户的关注者,但这是我第一次遇到指针问题。构建错误后panic:runtimeerror:invalidmemoryaddressornilpointerdereference[signal0xbcode=0x1addr=0x10pc=0xc9c26]代码packagemainimport("fmt""github.com/njasm/gosoundcloud")funcmain(){//callbackurlisoptional-nilinexamples,_:=gosoundcloud.NewSoundcloudApi("Cl

mongodb - mgo collection.Find(nil).All(&users) 不工作

我有下一个问题..我无法从我的mongo数据库(在docker容器中运行)中获取所有记录,这是我非常简单的代码:typeUserstruct{Emailstring`json:"email"bson:"email"`Passstring`json:"pass"bson:"pass"`}session:=dbConnect()collection:=session.DB("my_db").C("users")varusers[]Usererr:=collection.Find(nil).All(&users)iferr!=nil{log.Fatal("Mongocollectionfin

python - 当 Reader 类型作为输入时,gzip.NewReader() 返回 nil

我在解压缩之前压缩的字节流时遇到了问题。基本上,我尝试使用函数bytes.NewReader()创建一个阅读器,然后使用gzip.NewReader()函数解压流。最后,我想以字符串或字节格式返回实际值。我知道gzip.NewReader需要io.Reader作为输入,但是,据我所知,类型Reader实现了接口(interface)io.Reader。我认为这不会导致任何错误,但我想知道在这种情况下可能是什么问题。如果你帮我解决这个问题,我将不胜感激!如果您想知道这段文字是什么,"amZzRUR2NHVtcVpiZHNROHJiTTNYeGdUSndGTlVDZC9jaElSK1lXc

go - 是否有可能触发 "invalid memory address or nil pointer dereference"的错误?

我有一个偶尔会崩溃的应用程序:panic:运行时错误:无效的内存地址或零指针取消引用[信号SIGSEGV:分段违规代码=0x1地址=0x20pc=0x122e64a]跟踪一直导致返回语句,该语句返回一个结构和错误。新(“一些用于调试的文本:”+err.Error())该结构似乎没有任何可以取消引用指针的内容,但我重构了该函数,因此它使用了按引用传递并且不需要返回该函数;它只返回了errors.New()。panic还是发生了。我检查了函数并对其进行了更改,因此它只返回错误,没有错误。New()字符串加上err.Error()。现在我似乎不能再引起panic了……所以问题是:关于erro

go - 使用反射设置 nil *int32 结构字段

我正在尝试通过反射设置nil*int的值。在下面的示例中,replaceNilWithNegativeOne应该替换任何nil*int32字段(标记为grib:"foo")和一个指向-1的指针。但是,当代码运行时,reflect会出现panic,并显示panic:reflect:reflect.Value.Setusingunaddressablevalue。我在其他几个地方看到了几乎与我在这里问的完全相同的问题,例如:Usingreflect,howdoyousetthevalueofastructfield?Usingreflect,howdoyouinitializevalueo

go - 在方法或构造函数级别进行 Nil 处理?

我应该在构造函数中检查nil值然后设置一个未导出的结构字段,还是通过在方法级别检查nil使默认结构值有用?typeFoostruct{}func(f*Foo)Baz(){}varDefaultFoo=new(Foo)typeBarstruct{Foo*Foo}func(b*Bar)Baz(){ifb.Foo==nil{DefaultFoo.Baz()}else{b.Foo.Baz()}}或typeFoostruct{}func(f*Foo)Baz(){}varDefaultFoo=new(Foo)typeBarstruct{foo*Foo}funcNewBar(foo*Foo)*Bar

sqlite - 运行时错误 : invalid memory address or nil pointer dereference when Querying

我一直在研究用于身份验证的API,在尝试将其部署到服务器时,我偶然发现了这个奇怪的错误。该代码在我的笔记本电脑上运行得非常好,但是当我尝试部署它时,出现了这个错误:PANIC:runtimeerror:invalidmemoryaddressornilpointerdereferencegoroutine21[running]:github.com/urfave/negroni.(*Recovery).ServeHTTP.func1(0x7f5771b811e8,0xc4200980e8,0xc42009a870,0xc420138800)/home/linux/go/src/gith

go - 程序在主程序 block 中发现错误后出现 panic 。 panic : runtime error: invalid memory address or nil pointer dereference

我是golang的新手。在定义位置后trycatch主block中的错误后,我的程序出现panic。我在某处读过,添加defer.close()可能会有所帮助,但编译器再次说你的结构中不存在这样的定义帮助我解决它。typeIPInfostruct{IPstringHostnamestringCitystringCountrystringLocstringOrgstringPostalstring}funcmain(){ip:=getLocalIpv4()location,err:=ForeignIP(ip)iferr!=nil{fmt.Println("errorbro")}fmt.P

go - 使用beego验证码: invalid memory address or nil pointer dereference

我想在Beego下使用captcha生成验证码。但是它有错误无效的内存地址或零指针取消引用。有谁知道如何解决这个问题?谢谢。RequestMethod:GETRequestURL:/accounts/forgotpasswordRemoteAddr:127.0.0.1StackC:/Go/src/runtime/asm_amd64.s:573C:/Go/src/runtime/panic.go:505C:/Go/src/text/template/exec.go:137C:/Go/src/runtime/asm_amd64.s:573C:/Go/src/runtime/panic.go

go - 无效的内存地址或 nil 指针与 mgo 取消引用

packagemainimport("encoding/json""fmt""io/ioutil""net/http""github.com/gorilla/handlers""github.com/gorilla/mux""gopkg.in/mgo.v2")typeDataIgstruct{Memberstring`json:"Member"`Timestampfloat64`json:"Timestamp"`Namestring`json:"Name"`Bidstring`json:"Bid"`Offerstring`json:"Offer"`Changestring`json:"