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 getting exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getting exception in thread "main" java.lang.NoSuchMethodError: main error message" Watch "getting exception in thread "main" java.lang.NoSuchMethodError: main error message" New topic
Author

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

raj david
Greenhorn

Joined: Dec 21, 2009
Posts: 9
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

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41499
    
  53
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.


Ping & DNS - my free Android networking tools app
James Basller
Ranch Hand

Joined: Sep 07, 2008
Posts: 58
Hi

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

Thanks
James
raj david
Greenhorn

Joined: Dec 21, 2009
Posts: 9
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

Joined: Sep 07, 2008
Posts: 58
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
Marshal

Joined: Mar 22, 2005
Posts: 41499
    
  53
In addition to what James said, you should not put any user code into any of the JDK's directory.
raj david
Greenhorn

Joined: Dec 21, 2009
Posts: 9
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.



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting exception in thread "main" java.lang.NoSuchMethodError: main error message