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;
		try {
			str = br.readLine();
		} catch (IOException ioe) {
			System.out.println("IO error trying to read input from std. input!");
		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") {
		name = ReadIt.read();

Edited by Bladtman242: n/a

6 Years
Discussion Span
Last Post by Bladtman242

// 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.

Votes + Comments
Provided excatly what i needed.

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 :)

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? :)

Edited by Bladtman242: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.