If i have this in my main method: PrintWriter output = new PrintWriter(new FileWriter(args[1]));
and this in another method: output.println(currentLine);
and import java.io.*; obviously,
does anyone know why I am getting
cannot find symbol
symbol : variable output
location: class TestClass
output.println(currentLine);
The compiler tells you that the name (symbol)
outputis not defined in the scope (and enclosing scopes) where you want to use it. Based on the definitionit seems you define
outputin themain()function, but want to use it in a classTestClass, which is not valid asoutputis only defined withinmain()Assuming
main()is defined withinTestClassyou could defineoutputin the class, then assign its value inmain()and use it within the class later: