KirbyWallace
Programmer
For some reason, the line "FileToConsole.fileToConsole(cInputFile);" is
generating that pesky "non-static method fileToConsole() cannot be
referenced from a static context" error.
But I cannot figure out what makes it think .FileTest() is static.
Does it consider all constructors to be static by default?
I'm a complete beginner to java, but I have some background in other,
non-oo languages.
Note: PACKAGE and IMPORTs omitted for brevity **
//Main.java
//--------------------
// FileTest.java
//FileToConsole.java
//----------------------------
Any input appreciated!
generating that pesky "non-static method fileToConsole() cannot be
referenced from a static context" error.
But I cannot figure out what makes it think .FileTest() is static.
Does it consider all constructors to be static by default?
I'm a complete beginner to java, but I have some background in other,
non-oo languages.
Note: PACKAGE and IMPORTs omitted for brevity **
//Main.java
//--------------------
Code:
public class Main {
public static void main(String[] args) {
FileTest ft = new FileTest(args);
}
}
// FileTest.java
Code:
public class FileTest {
public FileTest(String[] args) {
String cInputFile = "test.txt";
FileToConsole.fileToConsole(cInputFile);
}
}
//FileToConsole.java
//----------------------------
Code:
public class FileToConsole {
public void fileToConsole(String cFile) {
try {
BufferedReader input = new BufferedReader(
new FileReader(
new File(cFile)));
String line = null;
while (( line = input.readLine()) != null) {
System.out.println(line);
}
}
catch (IOException ex) {
System.out.println("File Not Found");
}
}
}
Any input appreciated!