Hi all,

Trying to simply call method, (below) from another class and return the value found by the scanner. Please see below:

public int getInt(String prompt) {

		System.out.print(prompt + "a");
		//int result = in.nextInt();

		if  (in.hasNextInt()) {
			x = in.nextInt();
			y = in.nextInt();
			sum = x+y;

			System.out.print("sum" + sum);
		}

		int value = 5+5;
		return value;
	}

when I run this after compiling with no errors I receive the java.lang.NoSuchMethodError ... getInt(L/java/lang/String;)V at ...

Could you please advise how to return a value from the other class?

Much appreciated,

The doc for NoSuchMethodError says
"Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed."
Try deleting all your compiled .class files and re-compile everything.

Thanks James, that's removed the error. I just receive a 'cannot find symbol' message when trying to use the returned value. Do you know how I can use this value from this class in the other class now?

Solved this one:

int result = in.getInt("test");

7

Thanks :)

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.