0
votes

When I execute the following function with Remix I get the error: VM error: invalid opcode; the execution might have thrown. Unfortunately, this error doesn't tell me anything. I would be very grateful for any help.

function getAllTreatmentsForPatient() public view returns(address[]){ address[] memory providerAddresses = new address;

for(uint i = 0; i <= treatmentsPatient[msg.sender].length;  i++) {
    address a = treatmentsPatient[msg.sender][i].providerAddress;
    providerAddresses[i] = a;
}

return providerAddresses;

}`

1

1 Answers

0
votes

There is an error in for loop that you provide <= instead of <

You define i <= treatmentsPatient[msg.sender].length condition in for loop just replace it with i <treatmentsPatient[msg.sender].length then deploy contract again and try.