Results 1 to 6 of 6
  1. #1
    dragstang86 is offline Member
    Join Date
    Jun 2011
    Posts
    46
    Rep Power
    0

    Default Why is out.println giving me a compiling error?

    I am attempting to write an array List to a text file and I am getting a compiler error on the "println" portion of "out.println(p);" in the code below. The first for loop properly displays the data to the screen. The second for loops is where I am attempting to write the same data to a text file. I have seen out.println used in other programs. What am I missing? Thanks.

    Java Code:
        try {
            
        FileWriter fstream = new FileWriter("out.txt");
        BufferedWriter out = new BufferedWriter(fstream);  
        
            for (Polynomial p : sortedList) {
                System.out.println(p);
            }
            
            for (Polynomial p : sortedList) {
                out.println(p);
            }    
        }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    We don't read minds. Copy and paste the exact and full error message you get.

  3. #3
    dragstang86 is offline Member
    Join Date
    Jun 2011
    Posts
    46
    Rep Power
    0

    Default

    Sorry about that. It reads:

    "cannot find symbol
    symbol : method println(project.pkg1.Polynomial)
    location: class java.io.BufferedWriter
    out.println(p);"

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    BufferedWriter does not have a println method. Read the Java API to see what methods it does have. Don't forget to look at inherited methods as well.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,712
    Rep Power
    15

    Default

    "cannot find symbol" means (1) you have made a typo with the spelling of println(), (2) you have given it an argument of a type it does not accept or (3) there is no such method.

    (1) you can sort out for your self. For (2) and (3) have a look at the BufferedWriter API docs.

    ---------------

    To find all the classes that have a pritln() method you can also use the "Index" feature of the API docs.

  6. #6
    dragstang86 is offline Member
    Join Date
    Jun 2011
    Posts
    46
    Rep Power
    0

    Default

    Changed to PrintWriter and it works perfect now. Thanks for the help.

Similar Threads

  1. JavaCompiler giving an error WITHOUT ide
    By divs1210 in forum Advanced Java
    Replies: 9
    Last Post: 04-09-2011, 01:04 AM
  2. Java code giving error
    By alfarida in forum New To Java
    Replies: 3
    Last Post: 11-10-2010, 08:11 PM
  3. Replies: 1
    Last Post: 07-23-2010, 02:42 PM
  4. Pls check why my code is giving a runtime error
    By Beginner in forum New To Java
    Replies: 3
    Last Post: 05-26-2010, 12:32 AM
  5. Replies: 5
    Last Post: 01-17-2010, 12:14 AM

Posting Permissions

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