• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Exception in thread "main" java.util.NoSuchElementException

 
Greenhorn
Posts: 7
Python Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.




 
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
Python Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
Python Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To resolve this issue, it might help if you use the RandomAccessFile class.With this class you can write and read at random positions,check this Java RandomAccessFile Example
 
Marshal
Posts: 64707
226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I am afraid that is poor advice. The OP is reading a text file, so a random access file is the wrong class to use to read it. Please don't post such irrelevant tutorial links. This is the sort of thing you actually want with a Scanner:-
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!