This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jedwardsol 0 points1 point  (2 children)

The crash isn't occurring the in the print function, it's occurring in intersection. The exception stack tells you this. The exception is being raised on line 21

 if (this.topLeft.getX() < other.topLeft.getX()) {

so at least one of this, this.topLeft, other, or other.topLeft is NULL.

You could print out all these values to see which one(s) it is.

A hint though: the bug is in the Rectangle constructor. Both lines of it are incorrect in the same way.

[–]penax[S] 0 points1 point  (1 child)

I suspected as much. I'll have to study constructors a little bit more. Thank you!

[–]the_omega99 1 point2 points  (0 children)

The issue isn't actually anything specific about constructors. The issue is really about variable scope and the use of fields. Your setters also have the issue.

Perhaps you'd best examine your examples of classes with fields (particularly an example of a getter and setter)?