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 6 of 6

Thread: Why can I not execute the following code? When I try to run it, I get a message that there is no main method.

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Lightbulb Why can I not execute the following code? When I try to run it, I get a message that there is no main method.

    import java.util.*;
    import java.text.*;

    public class NumberFormatter
    {
    public static void main(String args[])
    {
    double amount = 1276789.34;
    double percent = 0.95;
    Locale india = new Locale("en", "IN");
    Locale america = new Locale("en", "US");
    Locale germany = new Locale("de", "DE");

    NumberFormat nfIndia = NumberFormat.getNumberInstance(india);
    NumberFormat nfAmerica = NumberFormat.getNumberInstance(america);
    NumberFormat nfGermany = NumberFormat.getNumberInstance(germany);
    System.out.println(nfIndia.format(amount));
    System.out.println(nfAmerica.format(amount));
    System.out.println(nfGermany.format(amount));

    nfIndia = NumberFormat.getCurrencyInstance(india);
    nfAmerica = NumberFormat.getCurrencyInstance(america);
    nfGermany = NumberFormat.getCurrencyInstance(germany);
    System.out.println(nfIndia.format(amount));
    System.out.println(nfAmerica.format(amount));
    System.out.println(nfGermany.format(amount));

    nfIndia = NumberFormat.getPercentInstance(india);
    nfAmerica = NumberFormat.getPercentInstance(america);
    nfGermany = NumberFormat.getPercentInstance(germany);
    System.out.print(nfIndia.format(percent));
    System.out.println(nfAmerica.format(percent));
    System.out.println(nfGermany.format(percent));

    }
    }


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Why can I not execute the following code? When I try to run it, I get a message that there is no main method.

    Can you post the exact error message? Also please read the forum FAQ about use of code tags.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Why can I not execute the following code? When I try to run it, I get a message that there is no main method.

    Class "NumberFormatter" does not have a main method.

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Why can I not execute the following code? When I try to run it, I get a message that there is no main method.

    Quote Originally Posted by TheCoder View Post
    Class "NumberFormatter" does not have a main method.
    Again, please look up use of [code] [/code] tags when posting code.

    Your code itself looks OK to me, so the problem is elsewhere. Are you sure that you're trying to run the correct class file, one that is from compiling the above code?

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Why can I not execute the following code? When I try to run it, I get a message that there is no main method.

    I will double check, thanks

  6. #6
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Why can I not execute the following code? When I try to run it, I get a message that there is no main method.

    It works for me. Probably left out a } in the original code.

Similar Threads

  1. Replies: 2
    Last Post: November 18th, 2012, 01:09 PM
  2. Main method/ class problem. I can't run any script!
    By BokBok in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2012, 05:14 PM
  3. Why my void run method cannot be execute?
    By 90th century in forum Threads
    Replies: 2
    Last Post: March 30th, 2012, 12:09 PM
  4. Replies: 6
    Last Post: July 21st, 2011, 07:45 AM
  5. how to execute a simple display without a main method
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: January 13th, 2010, 06:28 AM