Read the error properly
Most students skim the first line. The stack trace tells you the file, the line and the call path. Read it fully before changing anything.
Halve the problem
Do not guess at fixes. Find a point in the middle where you can check whether the state is still correct. Whichever half is wrong, halve that. Five halvings finds a bug in thirty lines.
Change one thing
Changing three things and seeing it work teaches you nothing, and you cannot undo the two that were unnecessary.
Reproduce before you fix
If you cannot make it happen on demand, you cannot know you fixed it. The bug that goes away on its own comes back during marking.