• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

The Dreaded "cannot be applied to" Error

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 coderanch, and to start class names with an uppercase letter. So it should be "public class License" instead of "class license".
 
Sarah Jane
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic