-2

How come in Eclipse if I don't specifically have a method called main and more specifically make that main method static, I get an error saying Exception in thread "main" java.lang.NoSuchMethodError: main? While in an Android Studio project, not only is there no method called main, the first method called in MyActivity.class is onCreate which isn't static.

Stuart
  • 59
  • 1
  • 1
  • 4
  • 1
    Some main method is not main. –  Sep 12 '14 at 20:57
  • 4
    Java requires a method `public static void main` with a `String[]` argument. This is standard Java and has nothing to do with Eclipse. See section 12.1.4 of the [JLS](http://docs.oracle.com/javase/specs/jls/se8/html/jls-12.html). Android is different because an application can have more than one entry point that the OS can call, and (I think) because Google just likes being different. – ajb Sep 12 '14 at 20:59
  • Related questions: [2 Main methods with different signatures](http://stackoverflow.com/questions/18194793/2-main-methods-with-different-signatures) and [Why main method is marked as public?](http://stackoverflow.com/questions/20666421/why-main-method-is-marked-as-public). – rgettman Sep 12 '14 at 21:02

1 Answers1

2

A Java class's main entry point will always have the signature:

public static void main(String args[])

With Android, you are not simply running a Java program, you are running code inside a container. Because of that, the container can set any entry point it likes.

nostromo
  • 1,435
  • 2
  • 17
  • 23