0
我目前正在使用Soundcloud包裝Go,我想打印用戶的追隨者,但這是我第一次遇到指針問題。恐慌:運行時錯誤:無效的內存地址或零指針解除引用
建設誤差
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x10 pc=0xc9c26]
代碼
package main
import (
"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 +0x3e6
net/http.(*Client).doFollowingRedirects(0x0, 0xc8200d0000, 0x4611c8, 0x0, 0x0, 0x0)
/usr/local/go/src/net/http/client.go:429 +0x66
net/http.(*Client).Do(0x0, 0xc8200d0000, 0x8, 0x0, 0x0)
/usr/local/go/src/net/http/client.go:188 +0xff
github.com/njasm/gosoundcloud.(*SoundcloudApi).do(0xc8200c8720, 0xc8200d0000, 0xc820012f00, 0x0, 0x0)
/Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:217 +0x4b
github.com/njasm/gosoundcloud.(*SoundcloudApi).Get(0xc8200c8720, 0xc820012f00, 0x22, 0x0, 0x1, 0x0, 0x0)
/Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:92 +0xe1
github.com/njasm/gosoundcloud.(*SoundcloudApi).GetUser(0xc8200c8720, 0x1, 0x417a80, 0x0, 0x0)
/Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:276 +0xc6
main.main()
/Users/ManuelDao/Documents/GoBot/src/GoBot/GoBot.go:24 +0x70
exit status 2
不是真的,要獲取數據,它不應該有必要用api登錄。這裏有一個鏈接到圖書館https://godoc.org/github.com/njasm/gosoundcloud – Juanvulcano
嗯,我只是嘗試了你的確切例子,它失敗了相同的零指針錯誤。用'PasswordCredentialsToken'獲得令牌後,一切正常。我已經在https://github.com/njasm/gosoundcloud上檢查了這個例子 –
我插入了你的代碼,它告訴我沒有定義的錯誤,在Go中我比較新。你是怎麼處理這個錯誤的? – Juanvulcano