部署时的 Solidity 错误消息:"Cannot Convert Undefined or Null to Object"

Solidity Error Message on Deployment: "Cannot Convert Undefined or Null to Object"

我正在学习 udemy 课程,但在我的代码中遇到错误:

创建彩票出错:无法将 undefined 或 null 转换为对象

为了测试这是否是我这边的错误,我使用了讲师提供的源代码,但是出现了同样的问题。我可以看到这段代码最近对其他学生有效。对正在发生的事情有什么建议吗?

教程源码如下:

//SPDX-许可证-标识符:GPL-3.0

pragma solidity >=0.5.0 <0.9.0;

合约彩票{

// declaring the state variables
address payable[] public players; //dynamic array of type address payable
address public manager; 


// declaring the constructor
constructor(){
    // initializing the owner to the address that deploys the contract
    manager = msg.sender; 
}

// declaring the receive() function that is necessary to receive ETH
receive () payable external{
    // each player sends exactly 0.1 ETH 
    require(msg.value == 0.1 ether);
    // appending the player to the players array
    players.push(payable(msg.sender));
}

// returning the contract's balance in wei
function getBalance() public view returns(uint){
    // only the manager is allowed to call it
    require(msg.sender == manager);
    return address(this).balance;
}

// helper function that returns a big random integer
function random() internal view returns(uint){
   return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, players.length)));
}


// selecting the winner
function pickWinner() public{
    // only the manager can pick a winner if there are at least 3 players in the lottery
    require(msg.sender == manager);
    require (players.length >= 3);
    
    uint r = random();
    address payable winner;
    
    // computing a random index of the array
    uint index = r % players.length;

    winner = players[index]; // this is the winner
    
    // transferring the entire contract's balance to the winner
    winner.transfer(getBalance());
    
    // resetting the lottery for the next round
    players = new address payable[](0);
}

}

只需复制并粘贴您在 remix 上提供的相同代码,即可部署合约实例。您可以像

那样尝试重新加载您的浏览器