Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Newbie question, simple program

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    4
    My Mood
    Fine
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post Newbie question, simple program

    My assignment was simply to see if this program would compile. It does. But going further, I wanted to run it. I get the error message "Error: Main method not found in class Clock, please define the main method as: public static void main(String[] args)". While I appreciate its polite tone, I cannot see anything wrong with the code (as I do have a main method defined). Can you point me in the right direction?

    class Clock {
       String time; 
       void setTime(String t) {
          time = t;
       }
     
       String getTime() {
          return time;
       }
    }
     
    class ClockTestDrive {
       public static void main(String [] args) {   
          Clock c = new Clock();
     
    	  c.setTime("1245");
    	  String tod = c.getTime();
    	  System.out.println("time: " + tod);
       }
    }


  2. #2
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: Newbie question, simple program

    You're trying to run class Clock. Do your run on class ClockTestDrive and it works just fine. You have to run the class with the main function.

  3. The Following User Says Thank You to Chris.Brown.SPE For This Useful Post:

    feelingroovyslc (March 20th, 2013)

  4. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    4
    My Mood
    Fine
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Newbie question, simple program

    <facepalm>

Similar Threads

  1. Simple question about a small program
    By azizmaiden in forum Java Theory & Questions
    Replies: 5
    Last Post: March 2nd, 2013, 05:52 PM
  2. newbie Question.....
    By Haseo in forum What's Wrong With My Code?
    Replies: 9
    Last Post: August 22nd, 2012, 09:10 AM
  3. Just a simple one for a newbie!!
    By scones73 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 16th, 2012, 12:09 AM
  4. Newbie: general question on trying to get a simple Pokemon game to work
    By willmer in forum Object Oriented Programming
    Replies: 7
    Last Post: July 13th, 2011, 08:33 AM
  5. Newbie needs help in simple servlet program
    By visitor1078 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 19th, 2009, 01:46 PM