• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

public static void main

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please tell me how to modify this code (taken directly from the SCJP Sun Certified Programmer for Java 6 Study Guide (Exam 310-065) book) so it executes?
I keep getting the error message java.lang.NoSuchMethodError: main
Exception in thread "main" when I try to execute the examples from this book. I am told it's because the code doesn't include the main method, but I haven't found any information on what the correct syntax is for including the main methods and the other methods in the class. Here is the code -- any advice on how to modify it would be appreciated. Other examples that only include the main method have worked when I've executed them so I don't think this is an issue with my Classpath.

class Zoo {public String coolMethod(){
return "Wow baby";
}

}
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can't write in the prompt java class if this class don't have the method main.
 
Lutin Verasoi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply. I understand that it needs the method main. My question was how should the code be modified so that the main method is included? The example I gave showed a class that contained the method called coolMethod. How do I include this in the class as well as the main method? I need to know the syntax and I can't seem to find an example of this anywhere.
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lutin Verasoi:
Can you please tell me how to modify this code (taken directly from the SCJP Sun Certified Programmer for Java 6 Study Guide (Exam 310-065) book) so it executes?
I keep getting the error message java.lang.NoSuchMethodError: main
Exception in thread "main" when I try to execute the examples from this book. I am told it's because the code doesn't include the main method, but I haven't found any information on what the correct syntax is for including the main methods and the other methods in the class. Here is the code -- any advice on how to modify it would be appreciated. Other examples that only include the main method have worked when I've executed them so I don't think this is an issue with my Classpath.

class Zoo {public String coolMethod(){
return "Wow baby";
}

}



Every program has to have at least one main method.

One way of doing this is (save as TestZoo.java):
/

You probably should be starting with a less advanced resource for learning the language than the exam study guide... you need to know the basics first.
 
Lutin Verasoi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you recommend one that would be a good precursor to the exam guide?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lutin Verasoi:
Can you recommend one that would be a good precursor to the exam guide?


Head First Java by Kathy Sierra and Bert Bates.
 
camilo lopes
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
core java is good guide too!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic