• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 799
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are probably trying to execute myClass:

Since the main method is in xxx, you must execute xxx:
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic