cannot be applied
Hello,
I am trying to call the method print();
Could someone please tell me what parameters i need to put in to get it to call? Right now its giving me a cannot be applied error.
The print() method is in the Coin class which is a different class. Thanks
Coin p =new Coin()//<-pretty sure i need this to call a method in a different class
Coin.print(not sure what to put here);
publicstaticvoid print(int ncount,int dcount,int qcount,LinkedList<String>nickels,LinkedList<String>dimes,
LinkedList<String>quarters,String type)//<method that needs to be called
[935 byte] By [
pberardi1a] at [2007-11-27 8:42:46]

It would help if you post the exact compiler error.
Sure thing. Thanks for your assistance. Here is the exact compiler error
init:
deps-jar:
Compiling 1 source file to C:\171 pberardi projects\pberardi 171DB4\build\classes
C:\171 pberardi projects\pberardi 171DB4\src\CoinBank.java:119: print(int,int,int,java.util.LinkedList<java.lang.String>,java.util.LinkedList<java.lang.String>,java.util.LinkedList<java.lang.String>,java.lang.String) in Coin cannot be applied to ()
Coin.print();
Note: C:\171 pberardi projects\pberardi 171DB4\src\CoinBank.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
BUILD FAILED (total time: 0 seconds)
> Sure thing. Thanks for your assistance. Here is the
> exact compiler error
>
> init:
> deps-jar:
> Compiling 1 source file to C:\171 pberardi
> projects\pberardi 171DB4\build\classes
> C:\171 pberardi projects\pberardi
> 171DB4\src\CoinBank.java:119:
> print(int,int,int,java.util.LinkedList<java.lang.Strin
> g>,java.util.LinkedList<java.lang.String>,java.util.Li
> nkedList<java.lang.String>,java.lang.String) in Coin
> cannot be applied to ()
>Coin.print();
> :\171 pberardi projects\pberardi
> 171DB4\src\CoinBank.java uses unchecked or unsafe
> operations.
> Note: Recompile with -Xlint:unchecked for details.
> 1 error
> BUILD FAILED (total time: 0 seconds)
Well, the compiler error tells you all you need to know: you're trying to call Coin.print() without any parameters but the print(...) method in the Coin class dictates that you should provide 3 int's followed by 3 LinkedLists's and finally one String.
Question: I'm not saying it's wrong, but why did you make that print method static?
> > Coin p = new Coin()//<-pretty sure i need this to
> call a method in a different class
> Coin.print(not sure what to put here);
>
What have you tried putting in there?
Honestly, because static methods are easier to call. Sorry Im really new.
> Honestly, because static methods are easier to call.> Sorry Im really new.just curious:Is this project a learning project, one you have given yourself in order to teach yourself java? or are you doing it for school or some other purpose?
I tried thisCoin.print(int ncount,int dcount,int qcount,LinkedList<String>nickels,LinkedList<String>dimes,LinkedList<String>quarters,String type);
> I tried this
> >
> Coin.print(int ncount,int dcount,int
> qcount,LinkedList<String>nickels,LinkedList<String>dim
> es,
>
> inkedList<String>quarters,String type);
>
>
>
You're listing parameters not arguments
> just curious:> Is this project a learning project, one you have> given yourself in order to teach yourself java? or> are you doing it for school or some other purpose?This is for school
> > You're listing parameters not argumentsI run into this alot. I cant get over this hump no matter what I read. I know there is a difference between a parameter and and argument, but I still have no clue what to put inside the () to call the method.
If my method is designed like so:
public void myMethod(int parameter)
{
....
}
Then I call it like so:
int myArg = 3;
myMethod(myArg);
not like
int myArg = 3;
myMethod(int myArg);
> Honestly, because static methods are easier to call.
Huh? Apperently you have no idea what static means.
> Sorry Im really new.
No need for sorry, just do some research if you don't know what something means/does. You should use the static keyword for methods that "do not directly belong" to a specific instance of a class.
Example:
class Coin {
// ...
static Coin createNickle() {
// return a Coin with a value of a nickle
}
}
now you can create a Coin object with the static above:Coin nickle = Coin.createNickle();
But a print() method suggests that you print the internal state of an instance (nickle is an instance of a Coin)
class Coin {
int value;
// ...
static void print() {
// from here you cannot print 'value', since the print() method is static!
// In other words: it does not belong to this instance
}
}
so you should do it like this:class Coin {
int value;
// ...
void print() {
// now print the 'value' variable
}
}
and you can now do:Coin nickle = Coin.createNickle();
nickle.print();
understand?
Of course, you can create new intance of a Coin by calling it's constructor (if there is one), it was only an example of me to do it with a static (factory) method.
> I run into this alot. I cant get over this hump no
> matter what I read. I know there is a difference
> between a parameter and and argument, but I still
> have no clue what to put inside the () to call the
> method.
Some friendly advice, and please don't take this the wrong way, but you are trying to learn java in a bad way. You are trying to learn by trial and error, and it is obviously not working.
I strongly advise you to get out of this and all java forums and get your head in a book. You are sorely deficient in the java basics, and you absolutely have to know them before you can progress. Only you can do that. And trying to use these forums to correct your errors will not correct your deficiencies.
> If my method is designed like so:
> >public void myMethod(int parameter)
> {
> ....
> /code]
> Then I call it like so:
> [code]
>int myArg = 3;
> myMethod(myArg);
>
> not like
> >int myArg = 3;
> myMethod(int myArg);
>
It works. Thanks. So args are just parameters without variable type? Interesting. Thanks again.
> It works. Thanks. So args are just parameters> without variable type? Interesting. Thanks again.no, (afaik) parameters are used when you define your method, arguments are used when you call your method.
> > Honestly, because static methods are easier to
> call.
>
> Huh? Apperently you have no idea what static means.
>
>
> > Sorry Im really new.
>
> No need for sorry, just do some research if you don't
> know what something means/does. You should use the
> static keyword for methods that "do not directly
> belong" to a specific instance of a class.
> Example:
> class Coin {
>// ...
> static Coin createNickle() {
>// return a Coin with a value of a nickle
>
> }
now you can create a Coin object with the
> static above:Coin nickle =
> Coin.createNickle();
>
> But a print() method suggests that you print the
> internal state of an instance (nickle is an instance
> of a Coin)
> class Coin {
>int value;
> // ...
>static void print() {
> // from here you cannot print 'value', since the
> print() method is static!
> // In other words: it does not belong to this
> instance
> }
>
so you should do it like this:class Coin
> {
>int value;
> // ...
>void print() {
>// now print the 'value' variable
> }
> }
and you can now do:Coin nickle =
> Coin.createNickle();
> nickle.print();
> understand?
>
> Of course, you can create new intance of a Coin by
> calling it's constructor (if there is one), it was
> only an example of me to do it with a static
> (factory) method.
I do understand that thank you. However in this case, that call to the print method is in main. And I think that main is always supposed to be static.
And petes...thank you for the friendly advise about getting my head in a book. I do read. The projects are quite difficult and course is very accelerated. I have to balance between learning and getting the assignments done. Besides if you bash your head against a wall enuf times youre bound to make a hole.
Let's be brutally honest. You don't know basic java sytax yet (static/instance, parameter/argument and method calls). You cannot and should not do anything else until this gap in your knowledge is rectified. But you need to do it now, asap, and before you do any more coding, before you keep up this wild goose chase of a program.
> However in this
> case, that call to the print method is in main. And
> I think that main is always supposed to be static.
Yes, but nobody said that you can call static methods only from a static method.
It's not from where you call the method that it's important.
If doSomething() is a static method of class Coin, you call it as such:
Coin.doSomething();
If doSomething() is a non-static method of class Coin, you call it as such:
Coin c = new Coin();
c.doSomething();
try not to put all too many arguments in the method. It's confused and hard to keep track. compile gives you error that might indicate that: you give wrong type of argument in the method. The bottom line: reduce arguments. use only print();