我是 golang 的新手,目前正在关注本教程和此处的源代码 - http://golang.org/doc/articles/wiki/part2.go
构建这个文件后,我得到了
calvin$ ./mywebwiki2
2012/07/23 17:12:59 http: panic serving [::1]:58820: runtime error: invalid memory address or nil pointer dereference
/usr/local/go/src/pkg/net/http/server.go:576 (0x3f202)
_func_003: buf.Write(debug.Stack())
/private/tmp/bindist454984655/go/src/pkg/runtime/proc.c:1443 (0x10c79)
/private/tmp/bindist454984655/go/src/pkg/runtime/runtime.c:128 (0x11745)
/private/tmp/bindist454984655/go/src/pkg/runtime/thread_darwin.c:418 (0x148b5)
/Users/calvin/work/gowiki/mywebwiki2.go:33 (0x2248)
viewHandler: fmt.Fprintf(w, "<h1>%s</h1><div>%s</div>", p.Title, p.Body)
/usr/local/go/src/pkg/net/http/server.go:690 (0x331ae)
HandlerFunc.ServeHTTP: f(w, r)
/usr/local/go/src/pkg/net/http/server.go:926 (0x34030)
(*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
/usr/local/go/src/pkg/net/http/server.go:656 (0x32fc1)
(*conn).serve: handler.ServeHTTP(w, w.req)
/private/tmp/bindist454984655/go/src/pkg/runtime/proc.c:271 (0xed7f)
2012/07/23 17:12:59 http: panic serving [::1]:58821: runtime error: invalid memory address or nil pointer dereference
知道我做错了什么导致这种明显的内存损坏吗?
最佳答案
第 36 行有一个被忽略的错误。如果您在浏览器中使用 URL http://localhost:8080/view 进行测试,该错误可能会显示 或 open .txt: no such file or directory/open foo.txt: no such file or directory 如果您在浏览器中使用 URL http://localhost:8080/view/foo 进行测试。在后一种情况下,您的工作目录中必须有一个文件“foo.txt”,此示例代码才能工作。之后代码似乎在本地对我有用。
可能有人应该填写有关忽略的错误值的问题。
关于戈朗 : runtime error: invalid memory address or nil pointer dereference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11609583/
我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("
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通过提示信息可以知道是个数组越界的问题。但是如图一中第二行话所说这个问题可能并不出在提示的代码段
我尝试通过以下命令在我的计算机上安装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)在我尝
在我们的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
我正在使用Ubuntu11.04在RubyonRails中开发一个应用程序。在应用程序中,我需要生成pdf文档。所以我正在使用wicked_pdf和wkhtmltopdf二进制gem。在我系统的开发环境中,一切正常。但是一旦我使用Phusion在CentOS5.6上部署应用程序乘客,当我尝试动态生成pdf时,出现以下错误:RuntimeError(wkhtmltopdf位置未知)我正在使用Ruby1.9.2.p136rails3.1.1任何帮助将不胜感激......谢谢。 最佳答案 另一种方法是通过Gemfile安装二进制文件。只需
我正在将开发中的应用程序从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
当我在Windows764位系统上运行bundleexecrspecspec/时,我收到以下错误:invalidswitchinRUBYOPT:-F(RuntimeError)我正在运行ruby1.9.2p136(2010-12-25)[i386-mingw32](安装在c:\ProgramFiles(x86)\Ruby192)和bundler1.0.15(作为rubygem安装).关于如何解决这个问题的任何线索?谢谢,本 最佳答案 Bundler不喜欢Ruby的路径包含空格这一事实。为了解决这个问题,我编辑了runtime
今天升级到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'我意识到这在最
我是ruby的新手,我正在尝试执行规范,但收到此错误:RuntimeError: :jsonisnotregisteredonFaraday::Request我正在尝试使用这个gem:https://github.com/Chicago/windyMacOSX10.7.4Ruby1.9.3,使用RVM 最佳答案 我刚刚在升级Faraday时遇到了这个问题。json请求中间件在0.8中从Faraday中移除。它现在位于faraday_middlewaregem中。您应该geminstallfaraday_middl
我最近从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