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;
}`