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 java.lang.NoSuchMethodError: main - What am I doing wrong? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.lang.NoSuchMethodError: main - What am I doing wrong?" Watch "java.lang.NoSuchMethodError: main - What am I doing wrong?" New topic
Author

java.lang.NoSuchMethodError: main - What am I doing wrong?

Bob Mann
Greenhorn

Joined: Mar 03, 2004
Posts: 1
I've created the following class but I keep getting the following error message:
========================================================
Exception in thread "main" java.lang.NoSuchMethodError: main
========================================================
class myClass
{
public void print()
{
System.out.println("M.A");
}
}

public class xxx
{
public static void main(String arg[])
{
myClass test = new myClass();
test.print();
}

}

=======================
Many thanks in advanced
Jeff Langr
author
Ranch Hand

Joined: May 14, 2003
Posts: 762
You are probably trying to execute myClass:

Since the main method is in xxx, you must execute xxx:


Books: Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
Alex Collins
Greenhorn

Joined: Mar 29, 2004
Posts: 6
Well you have not quite grasped the idea of method's and classes in java.
You do not need to classes here.
This will do the trick:
public class myClass{
public void printMyText(){
System.out.println("M.A");
}
public static void main(String[] args){
printMyText();
}
}
save,exit and then compile this program using:
>javac myClass.java
then run it using java:
java myClass
That will work.
Hope you understood
P.S:You really do not need to put the System.out.println in its separate method as there is very little code. However it is a good example of using methods...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.NoSuchMethodError: main - What am I doing wrong?
 
Similar Threads
Overriding rules... Please confirm!
CONSTRUCTOR DECLARATION
tipsmart mock
class loading
cannot find symbol error during compilation