File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes The Dreaded Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The Dreaded "cannot be applied to" Error" Watch "The Dreaded "cannot be applied to" Error" New topic
Author

The Dreaded "cannot be applied to" Error

Sarah Jane
Greenhorn

Joined: Nov 18, 2012
Posts: 3
Sooo.. my program wont compile. I'm getting this error message from hell:

license(java.lang.String[]) in Lic1 cannot be applied to ()
System.out.println(license());
^


Can someone give a poor java newbie a clue? Thanks so much! This site seems like a great resource.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42947
    
  70
You're calling the license method with no parameters, but the method is declared to take a String[] as parameter. Seeing that the method does not actually use the args parameter, you could remove that from the method declaration.

It looks like you're calling the license method recursively from within itself, though - that will cause problems at runtime. Specifically, you will see no output at all, and at some point the JVM will terminate with an error.
Sarah Jane
Greenhorn

Joined: Nov 18, 2012
Posts: 3
Ulf Dittmer wrote:You're calling the license method with no parameters, but the method is declared to take a String[] as parameter. Seeing that the method does not actually use the args parameter, you could remove that from the method declaration.

It looks like you're calling the license method recursively from within itself, though - that will cause problems at runtime. Specifically, you will see no output at all, and at some point the JVM will terminate with an error.


Thanks for your response, Ulf. This is my first time using "char" and feel like it's really screwing up my over all approach (maybe it's just my lack of sleep). I made some changes based on what I understood (think I understood) from your comments. The program now complies, but it gives me the following error when I attempt to run it: "Exception in thread "main" java.lang.NoSuchMethodError: main"



I'm so confused that I don't know what I'm confused about. I think my biggest issue is getting it to output? I don't know what to tell it to do despite hours of lectures and following the text book. I feel like a massive dolt.

Edit to ad: I did see what you meant about Args since there aren't any arguments, but I forget to remove it. It shouldn't result in the program running any differently should it? It just isn't needed.


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42947
    
  70
In order to execute a Java program you need to have a main method; in your code it's named license instead - that won't work. (Note that the main method does need to have a String[] parameter - so if you rename your license method to main you no longer have the option of removing the parameters. You can still ignore those parameters in the code, of course, as you're doing now.)

On an unrelated note, it's common practice to make classes that have a main method public, and to start class names with an uppercase letter. So it should be "public class License" instead of "class license".
Sarah Jane
Greenhorn

Joined: Nov 18, 2012
Posts: 3
Edit:
Soo.. I got the program to run as the following:



The only problem is that this is the output: ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789

I was expecting three random letter characters and three random number characters. Yikes.
Ivan Franko
Ranch Hand

Joined: May 30, 2011
Posts: 44
If you want see three random letter characters and three random number characters, why didn't you print them?

Array license contains your expected values. Print it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The Dreaded "cannot be applied to" Error