为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Go
波斯汪 2022-01-10 16:33:46
我目前正在使用用于 Go 的 Soundcloud 包装器,我想打印用户的关注者,但这是我第一次遇到指针问题。构建错误后panic: runtime error: invalid memory address or nil pointer dereference[signal 0xb code=0x1 addr=0x10 pc=0xc9c26]代码package mainimport (    "fmt"    "github.com/njasm/gosoundcloud")func main() {    //  callback url is optional - nil in example    s, _ := gosoundcloud.NewSoundcloudApi("Client_Id", "Client_Secret", nil)    var userID uint64 = 1    member, err := s.GetUser(userID)    if err != nil {               panic(err)     }    fmt.Println(member.Followers)}建成后goroutine 1 [running]:panic(0x3508c0, 0xc82000a0b0)    /usr/local/go/src/runtime/panic.go:481 +0x3e6net/http.(*Client).doFollowingRedirects(0x0, 0xc8200d0000, 0x4611c8, 0x0, 0x0, 0x0)    /usr/local/go/src/net/http/client.go:429 +0x66net/http.(*Client).Do(0x0, 0xc8200d0000, 0x8, 0x0, 0x0)    /usr/local/go/src/net/http/client.go:188 +0xffgithub.com/njasm/gosoundcloud.(*SoundcloudApi).do(0xc8200c8720, 0xc8200d0000, 0xc820012f00, 0x0, 0x0)    /Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:217 +0x4bgithub.com/njasm/gosoundcloud.(*SoundcloudApi).Get(0xc8200c8720, 0xc820012f00, 0x22, 0x0, 0x1, 0x0, 0x0)    /Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:92 +0xe1github.com/njasm/gosoundcloud.(*SoundcloudApi).GetUser(0xc8200c8720, 0x1, 0x417a80, 0x0, 0x0)        /Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:276 +0xc6main.main()        /Users/ManuelDao/Documents/GoBot/src/GoBot/GoBot.go:24 +0x70exit status 2
查看完整描述

1 回答

?
MMTTMM

TA贡献1869条经验 获得超4个赞

我以前从未使用过这个库,但看起来你忘记了自己的身份验证。


s, _ := gosoundcloud.NewSoundcloudApi("Client_Id", "Client_Secret", nil)

if err = s.PasswordCredentialsToken("your_email@something.com", "your_password"); err != nil {

    // handle err

}

可能是这样的?


查看完整回答
反对 回复 2022-01-10
  • 1 回答
  • 0 关注
  • 140 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信