This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

getting exception in thread "main" java.lang.NoSuchMethodError: main error message

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to java and i am reading head first java 2nd edition. I have come across SimpleDotCom exercise and I am getting the following message when I compile the javac SimpleDotComTestDrive.java...

Exception in thread "main" java.lang.NoSuchMethodError: main


All the files are in the same directory and two class files are showing. One for SimpleDotCom.class and the other SimpleDotComTestDrive.class

here are the files....












All the files are in the following directory....

c:/sun/sdk/jdk/bin

Where have I gone wrong?

Thanks in advance for your help

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

In the future, please reserve colored fonts to highlight short sections of a post, not the entire post. Also, please UseCodeTags (which I've done for you here). It's unnecessarily hard to read the code as it is, making it less likely that people will bother to do so.

How are you running the code, meanin, what are you typing at the command line? Only the SimpleDotComTester and Game classes have main methods, so you must be running one of those two.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Can you please post how you are running your Java program?

Thanks
James
 
raj david
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Apologies I will get familar with the tools available, I don't know how to do this yet.

I am coding in the following way....

C:\Sun\SDK\JDK\bin>javac SimpleDotComTestDrive.java
above complies but when I do the following
C:\Sun\SDK\JDK\bin> java SimpleDotCom
output shows as...
hit
failed


C:\Sun\SDK\JDK\bin>java SimpleDotCom
above complies but when I do the following
C:\Sun\SDK\JDK\bin> java SimpleDotCom
then this message is showing...
exception in thread "main" java.lang.NoSuchMethodError: main

But if I do Game one, which is
C:\Sun\SDK\JDK\bin>javac Game.java
then I get this error...
Game.java:1: package helpers does not exist
import helpers.GameHelper;
^

Thanks
 
James Basller
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I have seen your code there is no main method in SimpleDotCom class which is there in SimpleDotComTest.java. So, to run SimpleDotCom program you should have main method within that class then and then only JVM will come to know where should it has to start program execution.

Now, regarding game class I think that you are running downloaded or ready made code. Here, if your files are in Bin folder of JDK. But there is no package structure defined for your class that's why this error comes that package "helper" does not exist. You should put your classes in helper directory.

Thanks
James

raj david wrote:Hi,

Apologies I will get familar with the tools available, I don't know how to do this yet.

I am coding in the following way....

C:\Sun\SDK\JDK\bin>javac SimpleDotComTestDrive.java
above complies but when I do the following
C:\Sun\SDK\JDK\bin> java SimpleDotCom
output shows as...
hit
failed


C:\Sun\SDK\JDK\bin>java SimpleDotCom
above complies but when I do the following
C:\Sun\SDK\JDK\bin> java SimpleDotCom
then this message is showing...
exception in thread "main" java.lang.NoSuchMethodError: main

But if I do Game one, which is
C:\Sun\SDK\JDK\bin>javac Game.java
then I get this error...
Game.java:1: package helpers does not exist
import helpers.GameHelper;
^

Thanks

 
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 addition to what James said, you should not put any user code into any of the JDK's directory.
 
raj david
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will need couple of days I can't do this at the moment because of the hoilday season.

But thanks for your help.

Merry Christmas and Happy New Year to everyone.



 
New rule: no elephants at the chess tournament. Tiny ads are still okay.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic