草庐IT

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

coder 2024-07-08 原文

我目前正在使用 Go 的 Soundcloud 包装器,我想打印用户的关注者,但这是我第一次遇到指针问题。

构建错误后

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

最佳答案

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

s, _ := gosoundcloud.NewSoundcloudApi("Client_Id", "Client_Secret", nil)
if err = s.PasswordCredentialsToken("your_email@something.com", "your_password"); err != nil {
    // handle err
}

也许是这样的?

关于pointers - panic : runtime error: invalid memory address or nil pointer dereference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37233464/

有关pointers - panic : runtime error: invalid memory address or nil pointer dereference的更多相关文章

  1. ruby - RuntimeError(自动加载常量 Apps 多线程时检测到循环依赖 - 2

    我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("

  2. 【RuntimeError: CUDA error: device-side assert triggered】问题与解决 - 2

    RuntimeError:CUDAerror:device-sideasserttriggered问题描述解决思路发现问题:总结问题描述当我在调试模型的时候,出现了如下的问题/opt/conda/conda-bld/pytorch_1656352465323/work/aten/src/ATen/native/cuda/IndexKernel.cu:91:operator():block:[5,0,0],thread:[63,0,0]Assertion`index>=-sizes[i]&&index通过提示信息可以知道是个数组越界的问题。但是如图一中第二行话所说这个问题可能并不出在提示的代码段

  3. ruby - 通过 gem install mechanize 安装 gems 时显示错误 "invalid switch in RUBYOPT: -F (RuntimeError)" - 2

    我尝试通过以下命令在我的计算机上安装gem(Mechanize):>>geminstallmechanize--platform=ruby>>geminstallmechanize错误ERROR:Errorinstallingmechanize:ERROR:Failedtobuildgemnativeextension."C:/ProgramFiles/Ruby200-x64/bin/ruby.exe"extconf.rbC:/ProgramFiles/Ruby200-x64/bin/ruby.exe:invalidswitchinRUBYOPT:-F(RuntimeError)在我尝

  4. ruby-on-rails - RunTimeError:Rspec 2.10.1 中的 ActionController::RackDelegation for rails 3.1.4 应用程序 Controller - 2

    在我们的rails3.1.4应用程序中,rspec用于测试应用程序Controller中的公共(public)方法require_signin。这是require_signin方法:defrequire_signinif!signed_in?flash.now.alert="Loginfirst!"redirect_tosignin_pathendend这是rspec代码:it"shouldinvokerequire_signinforthosewithoutlogin"docontroller.send(:require_signin)controller{shouldredirec

  5. ruby-on-rails - rails : wkhtmltopdf RuntimeError (Location of wkhtmltopdf unknown) - 2

    我正在使用Ubuntu11.04在RubyonRails中开发一个应用程序。在应用程序中,我需要生成pdf文档。所以我正在使用wicked_pdf和wkhtmltopdf二进制gem。在我系统的开发环境中,一切正常。但是一旦我使用Phusion在CentOS5.6上部署应用程序乘客,当我尝试动态生成pdf时,出现以下错误:RuntimeError(wkhtmltopdf位置未知)我正在使用Ruby1.9.2.p136rails3.1.1任何帮助将不胜感激......谢谢。 最佳答案 另一种方法是通过Gemfile安装二进制文件。只需

  6. ruby - Rails 5 升级:在 ActionDispatch::ParamsParser (RuntimeError) 之后没有要插入的中间件 - 2

    我正在将开发中的应用程序从Rails4.2升级到Rails5beta1.1。应用程序在升级前运行良好。我已经完成了基本的升级步骤(更新Ruby、更新Rails和相关步骤:http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html)。Gemfile也已更新为最新的Gems。当我运行$railsmiddleware或$railsconsole或$railsserver时,出现以下错误:Nosuchmiddlewaretoinsertafter:ActionDispatch::ParamsParser.../.rvm/gems

  7. ruby - bundle exec rspec spec/=> RUBYOPT : -F (RuntimeError) 中的无效开关 - 2

    当我在Windows764位系统上运行bundleexecrspecspec/时,我收到以下错误:invalidswitchinRUBYOPT:-F(RuntimeError)我正在运行ruby​​1.9.2p136(2010-12-25)[i386-mingw32](安装在c:\ProgramFiles(x86)\Ruby192)和bundler1.0.15(作为ruby​​gem安装).关于如何解决这个问题的任何线索?谢谢,本 最佳答案 Bundler不喜欢Ruby的路径包含空格这一事实。为了解决这个问题,我编辑了runtime

  8. ruby-on-rails - REXML::RuntimeError(实体扩展变得太大) - 2

    今天升级到Ruby-1.9.3-p392后,REXML在尝试检索超过一定大小的XML响应时抛出运行时错误-一切正常,当接收到25条以下的XML记录时不会抛出错误,但是一旦达到特定的XML响应长度阈值,我收到此错误:Erroroccurredwhileparsingrequestparameters.Contents:RuntimeError(entityexpansionhasgrowntoolarge):/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/text.rb:387:in`blockinunnormalize'我意识到这在最

  9. ruby - RuntimeError: :json 未在 Faraday::Request 上注册 - 2

    我是ruby​​的新手,我正在尝试执行规范,但收到此错误:RuntimeError:         :jsonisnotregisteredonFaraday::Request我正在尝试使用这个gem:https://github.com/Chicago/windyMacOSX10.7.4Ruby1.9.3,使用RVM 最佳答案 我刚刚在升级Faraday时遇到了这个问题。json请求中间件在0.8中从Faraday中移除。它现在位于faraday_middlewaregem中。您应该geminstallfaraday_middl

  10. ruby-on-rails - rails : RuntimeError - can't modify frozen Array when running rspec in rails - 2

    我最近从v4.3升级到Rails5.1,现在在运行测试时遇到这个错误:Anerroroccurredwhileloading./spec/controllers/admin/capacity_charges_controller_spec.rb.Failure/Error:requireFile.expand_path('../../config/environment',__FILE__)RuntimeError:can'tmodifyfrozenArray我为每个测试文件都得到了它。触发错误的行来自rails_helper。我已经检查了Rails5.1示例repo协议(protoc

随机推荐