cannot be applied to () error message


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: cannot be applied to () error message

  1. #1
    Join Date
    Mar 2005
    Posts
    3

    cannot be applied to () error message

    I can't figure out what this means...please help
    thank you in advance for your help.

    add_items(java.lang.String[],java.lang.String[],double[],int[],int) in method13 cannot be applied to ()
    { add_items();
    ^
    1 error


    part of code
    {//open if
    if (b == 1)

    { add_items();
    }
    else if (b == 2)
    { String modifyString =JOptionPane.showInputDialog(null,

    "enter inventory number","inventory data",JOptionPane.QUESTION_MESSAGE);
    } else if (b == 3)
    { String deleteString =JOptionPane.showInputDialog(null,

    "enter inventory number","inventory data",JOptionPane.QUESTION_MESSAGE);
    }
    }//close if
    }// close modify




    public int add_items(String []number,String []name, double []cost, int []level, int count1)
    {// open add items
    int contn;
    String scontn, svalue;
    //items will be added until told to stop
    String output = "Enter 1 to continue and 0 to stop";
    scontn = JOptionPane.showInputDialog(null, output, " ",JOptionPane.QUESTION_MESSAGE);
    contn = Integer.parseInt(scontn);
    while (contn != 0)
    {//items added
    //items are added to the arrays
    count1 = count1 + 1;
    output = "Enter the Employee id Number";
    number[count1] = JOptionPane.showInputDialog(null, output, " ",JOptionPane.QUESTION_MESSAGE);
    output = "Enter the employee Name";
    name[count1] = JOptionPane.showInputDialog(null, output, " ",JOptionPane.QUESTION_MESSAGE);
    output = "Enter the salary";
    svalue = JOptionPane.showInputDialog(null, output, " ",JOptionPane.QUESTION_MESSAGE);
    cost[count1] = Double.parseDouble(svalue);
    output = "Enter the salary Level";
    svalue = JOptionPane.showInputDialog(null, output, " ",JOptionPane.QUESTION_MESSAGE);
    level[count1] = Integer.parseInt(svalue);
    output = "Enter 1 to continue and 0 to stop";
    scontn = JOptionPane.showInputDialog(null, output, " ",JOptionPane.QUESTION_MESSAGE);
    contn = Integer.parseInt(scontn);
    }//close items added

    return count1;
    }//close add items

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    Well when you define a method java creates what is known as a method signature. This is comprised of the name of the method and the parameters of the method. When put together the name and the parameters create the unique method signature.

    the error message is saying that it has the following method signature in the class definition...
    Code:
    add_items(java.lang.String[],java.lang.String[],double[],int[],int)
    This means it has a method called add_items that takes two String parameters, one double parameter and two int parameters. But in your code you tried to call a method as follows...
    Code:
    add_items()
    The compiler knows this method is called add_items, so it goes to it's list of methods and looks for the ones called add_items(). It can't find one called add_items() with no parameters though, just the one above with all of those parameters. This means it doesn't know what to with a method called add_items() but no parameters.

    When you call a method you have to put the right number of parameters into the parentheses, and they have to be in the right order. This means that if you have a method that wants a String parameter followed by an int parameter, you have to put them in the brackets in that order.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center