| 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: 758
|
|
You are probably trying to execute myClass: Since the main method is in xxx, you must execute xxx:
|
Author, Agile Java, 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...
|
 |
 |
|
|
subject: java.lang.NoSuchMethodError: main - What am I doing wrong?
|
|
|