• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with compile errors  RSS feed

 
Matrica Kovolunchy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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;

 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
fred rosenberger
lowercase baba
Bartender
Posts: 12562
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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?
 
Ankur Gargg
Ranch Hand
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in and out are not declared.
 
Matrica Kovolunchy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do I declare them?
 
Ankur Gargg
Ranch Hand
Posts: 55
Java jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Ok. Thank you. I guess I don't need the "in" and "out" anyways. Thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!