Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java help

  • 03-02-2013 01:00PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 501 ✭✭✭muff03


    No, TapeDeck.java.


  • Registered Users, Registered Users 2 Posts: 4,899 ✭✭✭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, Registered Users 2 Posts: 501 ✭✭✭muff03


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


  • Registered Users, Registered Users 2 Posts: 4,899 ✭✭✭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, Registered Users 2 Posts: 4,899 ✭✭✭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, Registered Users 2 Posts: 501 ✭✭✭muff03


    thanks for the help


  • Registered Users, Registered Users 2 Posts: 4,899 ✭✭✭robbiezero


    muff03 wrote: »
    thanks for the help

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


Advertisement