gogoWebsite

Encountering Cannot invoke ""

Updated to 17 days ago

Problem code:

int pre = map.floorKey(start);
int rear = map.lowerKey(end);
int pre_ = map.get(pre);
int rear_ = map.get(rear);

Execution code will be thrown: Cannot invoke "()" because the return value of "(Object)" is null, This is because null is returned when there is no return value, and int cannot be null. in addition,intValue()This is because Java finds that there is an int connection outside, and will automatically unbox and convert Integer to int. Because it cannot convert null, the exception will be thrown. Finally, just change it to Integer here.

Integer pre = map.floorKey(start);
Integer rear = map.lowerKey(end);
int pre_ = map.get(pre);
int rear_ = map.get(rear);

After this, it will be thrown when executing, the reason is that the previous pre is null,(null), so we have to change it to Integer here.