Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java help

Options
  • 03-02-2013 1:00pm
    #1
    Registered Users Posts: 501 ✭✭✭


    Hi guys, I'm at the beginning of my self taught Java apprenticeship and am in need of some help. I'm working from 'Head First Java' 2005, in chapter 2. The code is for a TapeDeck output generator (pg 42).

    I have the code correct as far as I can see from what I've been doing all along throughout the previous exercises, but after compiling I get the following:

    Static Error: This class does not have a static void main method accepting String[].

    Here's the code:
    class TapeDeck {
        boolean canRecord = false;
        void playTape() {
            System.out.println("tape playing");
        }
        void recordTape() {
            System.out.println("tape recording");
        }
    }
    class TapeDeckTestDrive {
        public static void main (String[] args) {
            TapeDeck t = new TapeDeck();
            t.canRecord = true;
            t.playTape();
            if (t.canRecord == true) {
                t.recordTape();
            }
        }
    }
    

    Any ideas? It seems to be with this chapter that I'm having problems with getting any output from my code. I'm using DrJava on a macbook running OSX 10.7.


Comments

  • Closed Accounts Posts: 3,596 ✭✭✭threein99


    muff03 wrote: »
    Hi guys, I'm at the beginning of my self taught Java apprenticeship and am in need of some help. I'm working from 'Head First Java' 2005, in chapter 2. The code is for a DrumKit output generator (pg 43).

    I have the code correct as far as I can see from what I've been doing all along throughout the previous exercises, but after compiling I get the following:

    Static Error: This class does not have a static void main method accepting String[].

    Here's the code:
    class TapeDeck {
        boolean canRecord = false;
        void playTape() {
            System.out.println("tape playing");
        }
        void recordTape() {
            System.out.println("tape recording");
        }
    }
    class TapeDeckTestDrive {
        public static void main (String[] args) {
            TapeDeck t = new TapeDeck();
            t.canRecord = true;
            t.playTape();
            if (t.canRecord == true) {
                t.recordTape();
            }
        }
    }
    

    Any ideas? It seems to be with this chapter that I'm having problems with getting any output from my code. I'm using DrJava on a macbook running OSX 10.7.

    Is the file saved as TapeDeckTestDrive .java ?


  • Registered Users Posts: 501 ✭✭✭muff03


    No, TapeDeck.java.


  • Registered Users Posts: 4,443 ✭✭✭robbiezero


    muff03 wrote: »
    No, TapeDeck.java.

    you dont need the class TapeDeckTestDrive.

    Remove that and have your main method in the TapeDeck class and it will work.

    Or move the TapeDeskTestDrive class to its own TapeDeskTestDrive.java class.


  • Registered Users Posts: 501 ✭✭✭muff03


    Spot on robbie, works perfect. Why would the book include
    class TapeDeckTestDrive
    
    as part of the code then?


  • Registered Users Posts: 4,443 ✭✭✭robbiezero


    muff03 wrote: »
    Spot on robbie, works perfect. Why would the book include
    class TapeDeckTestDrive
    
    as part of the code then?

    you were probably meant to call the file TapeDeckTestDrive.java I guess which would also work fine.


  • Advertisement
  • Registered Users Posts: 4,443 ✭✭✭robbiezero


    robbiezero wrote: »
    you were probably meant to call the file TapeDeckTestDrive.java I guess which would also work fine.

    Actually that is the correct answer to your question, not my previous one.


  • Registered Users Posts: 501 ✭✭✭muff03


    thanks for the help


  • Registered Users Posts: 4,443 ✭✭✭robbiezero


    muff03 wrote: »
    thanks for the help

    No bother. threein99 actually had the right answer before me.


Advertisement