CheatSheets-for-Developers icon indicating copy to clipboard operation
CheatSheets-for-Developers copied to clipboard

Fixing null pointer exception on the nextLine()

Open edd-ie opened this issue 11 months ago • 1 comments

Change Summary

NullPointerException caused by attempting to invoke the method hasMoreTokens() on a StringTokenizer object (st) that is null. This happens in the nextLine() method of your FastReader class.

Ensuring that st is properly initialized before calling hasMoreTokens() in the nextLine() method by modifying the nextLine() method to initialize st if it is null:

Checklist

If you haven't fulfilled the below requirements or even delete the entire checklist, your PR won't be reviewed and will be closed without notice.

General

  • [x] This Pull Request is all my own work. (You'll be blacklisted if you are caught for plagiarism.)
  • [x] I've read CONTRIBUTING.md
  • [x] I've made some valid changes to the CheatSheet, and they are not just minor changes.

Changes

Note: To mark the checkbox, put an x inside the [ ] (like this: [x]).

edd-ie avatar Nov 07 '24 22:11 edd-ie