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);
	}
}

// this appears to be causing the trouble

No. It is line 9. The error message points to line 17. There you call read with no arguments, while the definition of ReadIn.read requires one.

commented: Provided excatly what i needed. +3

God damn I feel stupid :)
I only just altered the member to take the String argument.
Then I corrected a few lines around line 7 and 9 and asumed that was it.

Thanks a bunch.
It's amazing how one can stare oneself blind sometimes :)

EDIT:
Another thing if I may.
When importing packages/objects, does the quantity make any difference at all?
Is import java.math.BigDecimal; better than import java.math.*; If I only intend to use that class?
Will it affect the final result (unlikely)?
Will it matter at compile time? perhaps take longer?
Or does it only matter when considering readability? :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.