jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java.util.NoSuchElementException" Watch "Exception in thread "main" java.util.NoSuchElementException" New topic
Author

Exception in thread "main" java.util.NoSuchElementException

Tor Ludgivsen
Greenhorn

Joined: Dec 15, 2012
Posts: 7

Hello, im new to this forum. And pretty new to java programming. I made this note system, so i have control over my notes at school. It will take in a name (philosophname) and store it in a .txt file named navn.txt and it also have a .txt file where i put in the notes in notat.txt.

my problem now is, when i add a new name i get this error. the name is stored in the file. and i can see the new name but i want to not get this error, so that i dont have to restart the program.






"None are more hopelessly enslaved than those who falsely believe they are free" - Johann Wolfgang von Goethe
Avery Torres
Greenhorn

Joined: Dec 15, 2012
Posts: 5
Take out all of your close System.in statements, ie "sc.close()" and "f.close()". Should work like a charm from there, also you might want to type check so that there is a catch in the menu if the user inputs a noninteger so that it doesn't just crash.
Tor Ludgivsen
Greenhorn

Joined: Dec 15, 2012
Posts: 7

omg, that easy o.O exactly why did that make that kind of error?
and btw, i will need the "f.close()" orelse it wont store into the .txt file + i have learned on school always to close the file you write to when you open it and finished with it.

but a new "problem" happend now. i do not get the error, but when i write new name i have to Exit(opt 10 in meny) to update the allname list.

yes tnx, will work with the checks on the meny.
Avery Torres
Greenhorn

Joined: Dec 15, 2012
Posts: 5
I believe the whole problem is coming from wanting to read and write the same file without having ever saved it. There are many ways to get around this one may be using a RandomAccessFile.
Tor Ludgivsen
Greenhorn

Joined: Dec 15, 2012
Posts: 7

exactly how do i split the context?
name;lastname;name-lastname
with this randomaccessfile is it the same way to split the context?

because later on, the note text will look like

note;key
here is the note bla bla bla;name-lastname
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.util.NoSuchElementException