• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with compile errors

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cannot for the life of me understand the problems the compiler is giving me are. What do I need to do to remedy these problems? I know that in.close() and out.close is needed, but I don't really know what those do. Any elaboration on those would be greatly appreciated. Thank you for your help!

P.s. (Figured I needed to add this, sorry) - I am trying to make a method that will print the values of the Array List "lines" one by one to an output file.

import java.io.PrintWriter;
import java.util.ArrayList;

 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matrica Kovolunchy wrote:P.s. (Figured I needed to add this, sorry)


It might also help if you tell us what the error messages are and which lines they are happening on.
 
Matrica Kovolunchy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, sorry. Should of added that.


C:\Users\ttr\Desktop>javac oop.java

oop.java:10: error: cannot find symbol
in.close();
^
symbol: variable in
location: class oop

oop.java:11: error: cannot find symbol
out.close();
^
symbol: variable out
location: class oop

oop.java:18: error: cannot find symbol
PrintWriter out = new PrintWriter(output.txt);
^
symbol: variable output
location: class oop

3 errors
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and what are "in" and "out" supposed to be? If they are variables, you need to declare them somewhere.

the compiler is also telling you it has no idea what "output" is. Is it supposed to be some other variable?
 
Ranch Hand
Posts: 55
jQuery Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in and out are not declared.
 
Matrica Kovolunchy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do I declare them?
 
Ankur Gargg
Ranch Hand
Posts: 55
jQuery Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.PrintWriter;
import java.util.ArrayList;

public class oop
{
public static void main (String[] args)
{
ArrayList<String> lines = new ArrayList<String>();
writeArrayListToFile(lines);

}


public static void writeArrayListToFile(ArrayList<String> lines)
{

PrintWriter out = new PrintWriter("output.txt");
for(int i =0; i<lines.size(); i++)
{
out.println(lines.get(i));
}

}
}

Here is the correct program
 
Matrica Kovolunchy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Thank you. I guess I don't need the "in" and "out" anyways. Thank you
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic