This is a code of a diary. I want the user to write something in the diary and this is gonna be the first page and gonna be put in a list. After writing enter the next page should be started and he writes something in the next page etc. I get errors over and over and I don't know why. After writing "enter" I get errors. I am new to java and all in all programming/coding (if it's the same). Sorry if it's a really dumb question i'm asking :/ Thank you for every advice. I am thankful for everything because I want to learn as much as I can for my university which would be in 1 year.
import java.util.ArrayList;
import java.util.Scanner;
public class NotizbuchKlasse{
public static void Pages(){
System.out.println("Tag 1 : Write something in your diary.");
System.out.println("Write enter if you are done writing.");
ArrayList<String> List = new ArrayList<String>();
String ListInList;
Scanner write;
do{
write = new Scanner(System.in);
ListInList = write.next();}
while (! ListInList.equals("enter"));
System.out.println("This is now your page. Your page is gonna be
created after writing something new.");
String y = ListInList;
List.add(y);
write.close();
Pages();
}
public static void main(String[]Args){
Pages();
}
}
day 1 : Write something in your diary.
Write enter if you are done writing.
hello diary
enter
This is now your page. Your page is gonna be created after writing something
new.
Exception in thread "main" day 1 : Write something in your diary.
Write enter if you are done writing.
java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at NotizbuchKlasse.Pages(NotizbuchKlasse.java:14)
at NotizbuchKlasse.Pages(NotizbuchKlasse.java:20)
at NotizbuchKlasse.main(NotizbuchKlasse.java:38)