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

There is no main method in class: Times - How do I resolve it?  RSS feed

 
Munjal Patel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to get following program work, it compiles fine, but when I try to run it on console, it gives me a message:

There is no main method in class: Times

Here is the code for your reference:

 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The signature of the main method, called at the start of an application is very specific... It must be...



Henry
 
Tommy Thomasson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Munjal!
Yes, As Henry said, the JVM is picky. While the compiler dosen't care (to a degree of course) how you declare the main method, the JVM always expects the main method to carry a String array as an argument. The name of the array does not matter. For example, you will often find the main method decalred as


but you are welcome to name the array anything, as long as it agrees with the conventions for declaring an array. Another legal example:



or prehaps...



This was a subject that was confusing to me when I began programming. Basically the String array argument is there in case you want to pass something to the java program from the command line.

I hope this was somewhat helpful

Tommy T.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Java Ranch

Added Some extra for Munjal Patel,

Everything in java is an Object.
There are two ways to used/call Objects in java.

1. The most common way is as a programming component that is instantiated by another program.
2. Another way to putting a main �method� in the class.

or you can use this link to clarify your answer.

Java Basics
[ August 09, 2006: Message edited by: saif uddin ]
 
Munjal Patel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohh ok, got it!

Thanks a bunch
 
Benjamin Lau
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did consider that the name of the array should be "args".

Thanks! I got a lot.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!