Scanner Bug (Tried Everything)
So I ask users through input through these two methods:
The error occurs in the switch statement below, I think it happens when I ask for a byte, then a string, or vice versa (I forget):
bytInput also used a method switch is in a loop, if you need code more pls ask
6 Replies
⌛
This post has been reserved for your question.
Hey @austrianpainter! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Can you elaborate on what happens?
It's probably because of the scanner.next stuff. Generally speaking that can cause issues because the non-parsed data stays in the input stream and it has to be discarded via a call to nextLine. You can confirm this by running this piece of code:
I believe the best way to avoid this is to just use nextLine() on your scanner and then parsing to the appropriate type as that advances the scanner past the line no matter what.
For this you can make a utility function that looks something like this and should work for all number types:
Of course if you don't want to do this you can just do it like you have so far, except replace the calls to nextByte or next whatever with nextLine and parse after that.
I am guessing that's what is going on anyway
Thank you so much!
Sorry for the little detail it was 3am for me when I asked.
I might do that (which my teacher kind of dissaproves of) or just make an entirely new Scanner object in the method
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@1233964909084147753>.