Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

main()  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My class don't have main() . So when i run the particular class i got the following run time error:
Exception in thread "main" java.lang.NoSuchMethodError: main

but i want to see my System.out.println..output....without using main()...
Any way?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add a main(), and just have main() call whatever methods you want to run. There's no other way.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is in fact.
Instantiate the class from some other class that does have a main method with the correct signature and call the methods from that
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Jeroen...

how is using main from another class "not using main"?? You're still using it in class B, you're just not using it in class A. I don't think that counts as "(not) using main()".

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could be charged as an accessory for showing you this, but...

Note: The System.exit(0) statement allows the application to get out of Dodge before the Sheriff slaps it with a "NoSuchMethodError."
[ March 03, 2005: Message edited by: marc weber ]
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now that's entertainment!
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Boo! Hiss! That's pretty sneaky, man! I'll bet you've entered code obfuscation contests before. I like it, though. It shows a pretty good understanding of the Java language. I definitely learned something today!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!