#My code does not input the file nor print the output
21 messages ยท Page 1 of 1 (latest)
โ This post has been reserved for your question.
Hey @pure sparrow! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
is it displaying any error ?
yes
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1371)
at StudentsManager.main(StudentsManager.java:49)
C:\Users\alawy\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
check if the scanner has a next token by calling scanner#hasNext
I suppose the input file contains the commands ?
yes it does
could you upload the input file
Your first scanner.nextLine() consumes the entire first line Add student: ID1, Ahmed, CS101, 20 not only the Add student part.
What I would do:
while scanner has another line:
read the line and store it in a variable
using the line stored in the variable parse the command and execute it.
that way you keep interaction with the scanner to a minimum and it will be easier to parse the command.
sorry i am a bit frustrated but i'm implementing what you suggested hopefully it will solve the issue
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.
ok it solved the error part but still no output
at no point in the program you are writing to your output file. At the very end, after all commands are processed you iterate over the entirety of the Linked list write each Student to the output file
try to implement like I suggested here. You only introduced a while loop that checks if th scanner has another line, that's the first step
๐ค Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.