I am following a series of programming challenges for beginners,
this challenge requires interactive commandline input which is a pain in java.
Therefore I've made a small class in another file to handle the user input.
When I try to compile the main class ('external' class compiles without problems) I get this error:
Input.java:17: read(java.lang.String) in ReadIn cannot be applied to ()
name = ReadIt.read();
^
1 error
If anyone could nod me off in the right direction it would be much appreciated.
The 'external' class (is there an actual name for these?) looks like this:
import java.io.*;
public class ReadIn {
public ReadIn() {
}
public String read(String q) {
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str = null;
System.out.print(q);
try {
str = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying to read input from std. input!");
System.exit(1);
}
return str;
}
}
And this is what the main class looks like so far. It's fairly short so no real //comments yet :) hope it's ok.
NOTE: I doubt it will be necessary to read and understand the entire class, as the problem appears to lie in the interaction between the two classes :)
public class Input {
public static void main (String[] args) {
System.out.println("\nPlease type in your details, as adviced.");
ReadIn ReadIt = new ReadIn();
String name = ReadIt.read("\nName"); // this appears to be causing the trouble
while (name.trim().length() == 0 ) {
if (name == "quit") {
System.out.println("Terminating...");
System.exit(0);
}
name = ReadIt.read();
}
System.exit(0);
}
}