Need help with PrintWriter!
Hello, my first post. It doesn't write anything to the file.
Sry for the variables, it's in Swedish:^):
Code:
PrintWriter skrivfil = new PrintWriter(new BufferedWriter(new FileWriter("LagerV.txt")));
enrad = readfil.nextLine();
Artikel a2 = new Artikel(enrad);
skrivfil.println(a2.geteanKod() + a2.getvaruNamn() + a2.getlagerVr());
Now when it's running I get this problem.
Code:
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1516)
at lagerV.main(lagerV.java:27)
I've tried if it prints out anything in the file only by not giving the variables no values, I get null.
Code:
PrintWriter skrivfil = new PrintWriter(new BufferedWriter(new FileWriter("LagerV.txt")));
skrivfil.println(a2.geteanKod() + a2.getvaruNamn() + a2.getlagerVr())
Re: Need help with PrintWriter!
Quote:
Originally Posted by
PapaEcho
Hello, my first post. It doesn't write anything to the file.
And welcome to java-forums.org!
Quote:
Code:
PrintWriter skrivfil = new PrintWriter(new BufferedWriter(new FileWriter("LagerV.txt")));
enrad = readfil.nextLine();
Artikel a2 = new Artikel(enrad);
skrivfil.println(a2.geteanKod() + a2.getvaruNamn() + a2.getlagerVr());
Now when it's running I get this problem.
Code:
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1516)
at lagerV.main(lagerV.java:27)
I've tried if it prints out anything in the file only by not giving the variables no values, I get null.
Code:
PrintWriter skrivfil = new PrintWriter(new BufferedWriter(new FileWriter("LagerV.txt")));
skrivfil.println(a2.geteanKod() + a2.getvaruNamn() + a2.getlagerVr())
This:
Code:
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1516)
at lagerV.main(lagerV.java:27)
Tells you that the problem is not with the PrintWriter but with the Scanner object, readfil. It is trying to read in a line, but no line exists.
Re: Need help with PrintWriter!
Thx! I got it working! But it's strange, I only manage with success run it on Mac! It doesn't work on Windows? (Windows trash! ;D) I can compile it and run it, but I get this error...
What is wrong? My constructor? Just tell me if you want to see the code.
Code:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at Artikel.<init>(Artikel.java:19)
at LagerV.main(LagerV.java:22)