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

Thread: Failed to compile, Main Method Not found, assistance please.

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Failed to compile, Main Method Not found, assistance please.

    class DrumKit {

    boolean topHat = true;
    boolean snare = true;

    void playTopHat() {
    System.out.println("ding ding da-ding");
    }
    void playSnare() {
    System.out.println("bang bang ba-bang");
    }


    class DrumKitTestDrive {
    public static void main(String [] asrgs) {

    DrumKit d = new DrumKit();
    d.playSnare();
    d.snare = false;
    d.playTopHat();

    if (d.snare == true) {
    d.playSnare();
    }
    }
    }
    }

    --- Update ---

    This code was taken directly from an activity in the headfirst java book, when run through geany, it says that I am not allowed to have a static inside and inner class??


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Failed to compile, Main Method Not found, assistance please.

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

    The main() method must be in a top-level public class of the same name as the file in which the source code is stored.

  3. #3
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    73
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: Failed to compile, Main Method Not found, assistance please.

    This code was taken directly from an activity in the headfirst java book, when run through geany, it says that I am not allowed to have a static inside and inner class??
    I suspect that these two classes are not intended to be in the same file/compilation unit. Split DrumKit and DrumKitTestDrive into their own files in the same directory. Or modify the file so the inner reference is properly referenced in a static manner from the static outer reference. Or make sure main() is declared in the top-level type.

    This is a fancy way of saying that if this is out of a book exactly as you show here, and it is supposed to compile, then the book has bugs. If this is a way to illustrate static and non-static refs to inner and outer classes, then it needs to be tweaked a little to achieve that.
    Last edited by jdv; August 22nd, 2014 at 01:54 PM.

  4. #4
    Junior Member
    Join Date
    Sep 2014
    Location
    Mumbai
    Posts
    10
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Failed to compile, Main Method Not found, assistance please.

    You have to close the DrumKit class first before starting DrumKitTestDrive i.e. } is missing before the DrumKitTestDrive class starts and remove the last } in the end.

Similar Threads

  1. Experiencing problems w/ Scanner & main, open to any assistance!
    By BlackStones in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 9th, 2014, 01:23 PM
  2. i get a error Failed to load Main-Class manifest attribute
    By Deepdiddi in forum Object Oriented Programming
    Replies: 0
    Last Post: January 17th, 2014, 08:25 AM
  3. Failed to compile, URGENT please help. Can't compile using JDK
    By sauyang in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 18th, 2013, 07:16 AM
  4. Error: Main method not found! Please help!
    By adnan.alvee in forum What's Wrong With My Code?
    Replies: 12
    Last Post: March 11th, 2013, 07:03 PM
  5. Remaining compile errors: no suitable method found for & cannot find symbol
    By ChuckLep in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 12th, 2011, 03:33 PM