Go 运行Hello Couchbase应用程序时出现紧急运行时错误

Go 运行Hello Couchbase应用程序时出现紧急运行时错误,go,couchbase,Go,Couchbase,按照此处给出的说明安装go SDK 1.6: 创建了Hello Couchbase应用程序,如上页所示。运行应用程序时,程序在以下行出现恐慌:微微一笑: 用于行。下一行(&row){ 并产生以下错误: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x12d66b2] Go版

按照此处给出的说明安装go SDK 1.6: 创建了Hello Couchbase应用程序,如上页所示。运行应用程序时,程序在以下行出现恐慌:微微一笑: 用于行。下一行(&row){ 并产生以下错误:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x12d66b2]
Go版本打印以下内容:Go版本go1.12.9 darwin/amd64 macOS版本10.14.6

一旦安装了SDK,就可以运行这个简单的代码段 展示了它的一些特性

为简洁起见,省略了错误检查


在围棋中,始终检查错误。如果检查错误,会发生什么错误

错误

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

通常表示错误被忽略。

将行:rows,:=bucket.execute1qlquery(query,[]接口{}{“非洲燕子”})更改为行,err:=bucket.execute1qlquery(query,[]接口{}{“非洲燕子”})以处理错误。还将下面一行中的bucketname更改为bucket的实际名称:query:=gocb.NewN1qlQuery(“从bucketname中选择*,其中利息为$1”)。原始示例代码如下: