Programs can fail in a lot of ways (and if you don't know that already, you'll learn it soon!). Towards the end of this course, one thing that we've seen happening is something along these lines:
Of course there's more than one way to find yourself staring at your program, but under these circumstances, here's one possible guess:
You have two (or more) BufferedReaders in your program, and it's not working.
A BufferedReader accepts input from System.in. It may use up all the input it has read, or it may have some still lying around waiting to be used later. If you have two BufferedReaders, the one with the input you need may not be the one you're asking for input.
The issue is not how many declarations of BufferedReaders you have. It's how many BufferedReader objects you have.
For example, you might have just this one mention of the type BufferedReader in your program:
private BufferedReader reader = new BufferedReader(...);
If this is inside a class "Flotsam", then every time you create an object of type Flotsam you also create a new BufferedReader. You're in trouble.
Have just one BufferedReader in your program, and share it as needed between classes. Often, you'll do all your input in one place, so that isn't a problem.
But if you've designed your program so that each object of type Flotsam needs really should do its own input, you need to allow each one to have access to that shared BufferedReader. In that case, create the BufferedReader somewhere else, and then pass it to a Flotsam when you create it:
class Flotsam { private BufferedReader reader; public Flotsam (BufferedReader br, ...) { this.br = br; ... } }
And so on.
Some IDEs manage input so that it doesn't get saved up and then given to the wrong recipient. They don't all do that, however, and they don't have to: the Java specification only says that if you have a single BufferedReader you'll be OK. It doesn't say that if you have more than one BufferedReader you won't be OK.
That is, why not make BufferedReader's methods static, instead of making us create objects when there can only be a single one? That's what "static" is for, isn't it?
Sort of. You can only have one BufferedReader for a single source of input, such as the keyboard. But if you take input from more than one source -- for example, if you have three files open at once -- then you'll need a BufferedReader for each source.
But that would be unusual in CSC108H.