Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Need help with PrintWriter!

  1. #1
    PapaEcho is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default Need help with PrintWriter!

    Hello, my first post. It doesn't write anything to the file.
    Sry for the variables, it's in Swedish
    Java 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.
    Java 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.
    Java Code:
    PrintWriter skrivfil = new PrintWriter(new BufferedWriter(new FileWriter("LagerV.txt")));
    
    skrivfil.println(a2.geteanKod() + a2.getvaruNamn() + a2.getlagerVr())

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help with PrintWriter!

    Quote Originally Posted by PapaEcho View Post
    Hello, my first post. It doesn't write anything to the file.
    And welcome to java-forums.org!

    Java 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.
    Java 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.
    Java Code:
    PrintWriter skrivfil = new PrintWriter(new BufferedWriter(new FileWriter("LagerV.txt")));
    
    skrivfil.println(a2.geteanKod() + a2.getvaruNamn() + a2.getlagerVr())

    This:

    Java 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.
    tangel likes this.

  3. #3
    PapaEcho is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default 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.
    Java 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)

Similar Threads

  1. printwriter
    By sope in forum New To Java
    Replies: 2
    Last Post: 05-09-2011, 07:57 PM
  2. java PrintWriter
    By miko5054 in forum New To Java
    Replies: 3
    Last Post: 05-08-2011, 01:25 PM
  3. printWriter problem
    By Lund01 in forum Advanced Java
    Replies: 6
    Last Post: 10-14-2010, 01:28 PM
  4. Help with printwriter class
    By eel in forum New To Java
    Replies: 9
    Last Post: 09-19-2010, 02:04 PM
  5. Help with printwriter.
    By Addez in forum New To Java
    Replies: 2
    Last Post: 10-30-2009, 01:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •