File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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

Bob Mann

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()

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


Many thanks in advanced
Jeff Langr
Ranch Hand

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

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

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

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(){
public static void main(String[] args){
save,exit and then compile this program using:
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:
subject: java.lang.NoSuchMethodError: main - What am I doing wrong?
It's not a secret anymore!