5 Replies - 1316 Views - Last Post: 12 January 2010 - 10:16 AM Rate Topic: -----

#1 Moogoo  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 82
  • Joined: 06-January 10

Method Calling error

Posted 12 January 2010 - 08:59 AM

I am having difficulty in calling a method. I have compiled the method by itself and have no errors, but when I add the main method, I have a calling error:
import javax.swing.JOptionPane;

public class Palindrome
{
	public static void main(String[] args)
	{
		int userNumber;

		userNumber = retrieveInput();
	}
	public static int retrieveInput(String userInput, int convertString)
	{
		try
		{
			userInput = JOptionPane.showInputDialog("Enter a five digit number");
			convertString = Integer.parseInt(userInput);
			if (convertString <= 9999 || convertString > 99999) throw new Error();
		}
		catch (Error e)
		{
			JOptionPane.showMessageDialog(null,"Number must be five(5) digits.", "Error",JOptionPane.ERROR_MESSAGE);
		}
		return convertString;
	}

}



The error I get is this: The method retrieveInput(String, int) in the type Palindrome is not applicable for the arguments ()

If someone could just let me know in plain English what I'm doing wrong, that would be great.

Is This A Good Question/Topic? 0
  • +

Replies To: Method Calling error

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: Method Calling error

Posted 12 January 2010 - 09:00 AM

retrieveInput requires two parameters. You called it with zero, hence the error.
Was This Post Helpful? 0
  • +
  • -

#3 Moogoo  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 82
  • Joined: 06-January 10

Re: Method Calling error

Posted 12 January 2010 - 09:17 AM

View PostKYA, on 12 Jan, 2010 - 08:00 AM, said:

retrieveInput requires two parameters. You called it with zero, hence the error.


I see your point, so I added the arguments into the main method here:
import javax.swing.JOptionPane;

public class Palindrome
{
	public static void main(String[] args)
	{
		int userNumber;
		

		userNumber = retrieveInput(String, int);
	}
	public static int retrieveInput(String userInput, int convertString)
	{
		try
		{
			userInput = JOptionPane.showInputDialog("Enter a five digit number");
			convertString = Integer.parseInt(userInput);
			if (convertString <= 9999 || convertString > 99999) throw new Error();
		}
		catch (Error e)
		{
			JOptionPane.showMessageDialog(null,"Number must be five(5) digits.", "Error",JOptionPane.ERROR_MESSAGE);
		}
		return convertString;
	}
	
}



Now I'm getting this error:
1. ERROR in Palindrome.java (at line 15)
userNumber = retrieveInput(String, int) ;

Syntax error on token "int", invalid Expression

What am I doing wrong?

This post has been edited by Moogoo: 12 January 2010 - 09:18 AM

Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: Method Calling error

Posted 12 January 2010 - 09:22 AM

You need to actually pass data/variables not just type declarations.

Based on the method, there isn't any reason to pass variables.


 public static int retrieveInput(){
	 String userInput;
	 int convertString;
		try
		{
			userInput = JOptionPane.showInputDialog("Enter a five digit number");
			convertString = Integer.parseInt(userInput);
			if (convertString <= 9999 || convertString > 99999) throw new Error();
		}
		catch (Error e)
		{
			JOptionPane.showMessageDialog(null,"Number must be five(5) digits.", "Error",JOptionPane.ERROR_MESSAGE);
		}
		return convertString;
	}


Was This Post Helpful? 1
  • +
  • -

#5 Simple_Condolences  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 138
  • Joined: 10-January 10

Re: Method Calling error

Posted 12 January 2010 - 10:02 AM

import javax.swing.JOptionPane;

public class Palindrome
{
	public static void main(String[] args)
	{
		int userNumber;

		userNumber = retrieveInput(); //you aren't sending any parameters
	}
	public static int retrieveInput(String userInput, int convertString) //requires two parameters, types integer and String
	{
		try
		{
			userInput = JOptionPane.showInputDialog("Enter a five digit number");
			convertString = Integer.parseInt(userInput);
			if (convertString <= 9999 || convertString > 99999) throw new Error();
		}
		catch (Error e)
		{
			JOptionPane.showMessageDialog(null,"Number must be five(5) digits.", "Error",JOptionPane.ERROR_MESSAGE);
		}
		return convertString;
	}

}



The error I get is this: The method retrieveInput(String, int) in the type Palindrome is not applicable for the arguments ()

If someone could just let me know in plain English what I'm doing wrong, that would be great.
[/quote]

KYA told you very clearly here below.

Quote

View PostKYA, on 12 Jan, 2010 - 08:00 AM, said:

retrieveInput requires two parameters. You called it with zero, hence the error.



View PostKYA, on 12 Jan, 2010 - 08:22 AM, said:

You need to actually pass data/variables not just type declarations.

As they both said, you didn't give parameters. a parameter consists of a variable name (x) and a data type(int). You only supplied the data types and no actual variables. You need to give a parameter that looks something like this ( int x, String y)

 public static int retrieveInput(){
	 String userInput;
	 int convertString;
		try
		{
			userInput = JOptionPane.showInputDialog("Enter a five digit number");
			convertString = Integer.parseInt(userInput);
			if (convertString <= 9999 || convertString > 99999) throw new Error();
		}
		catch (Error e)
		{
			JOptionPane.showMessageDialog(null,"Number must be five(5) digits.", "Error",JOptionPane.ERROR_MESSAGE);
		}
		return convertString;
	}


[/quote]
... actually... well, for future reference, you need to make sure you pass all needed parameters if the method requires data from outside its scope. KYA is right though, you don't need to pass any parameters to do what you're trying to do.

- Zach
Was This Post Helpful? 0
  • +
  • -

#6 Moogoo  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 82
  • Joined: 06-January 10

Re: Method Calling error

Posted 12 January 2010 - 10:16 AM

Thanks, I was declaring variable types in the argument parameters when I didn't need to and at the same time causing a problem in the main method. Thanks for your help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1