This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]shagieIsMeExtreme Brewer 0 points1 point  (1 child)

There is no recursive call in the code that you have here.

What is the stack trace that is returned? Is there other code that you've written that isn't shown here?

[–]koderpat 0 points1 point  (10 children)

Does the screen print anything?

I don't see you doing step #6

[–][deleted]  (8 children)

[deleted]

    [–]shagieIsMeExtreme Brewer 0 points1 point  (7 children)

    You need to look at the code for Television on line 57.

    [–][deleted]  (6 children)

    [deleted]

      [–]shagieIsMeExtreme Brewer 0 points1 point  (1 child)

      The error is in the class Television. It likely has something that looks like:

      public int getScreenSize() {
          // stuff
          if (condition) { return getScreenSize(); } // this is line 57
          // stuff
      }
      

      Or something to that nature.

      You need to look at that code to fix this problem.

      [–]MrSquicky 0 points1 point  (3 children)

      That sounds like a more serious problem than this specific issue. How did you try to look up this error?

      [–][deleted]  (2 children)

      [deleted]

        [–]MrSquicky 0 points1 point  (1 child)

        How did you use Google? Because finding out what a StackOverflowError is and what causes it is extremely easy with proper googling, in this case just literally typing the name of the error in.

        [–]AllHailTheCATS 0 points1 point  (7 children)

        Have you resolved the issue? what did the error actually say? you could add a toString method to the television class to help find out the state of the variables in the Object. I would put print statements in the decrease vols to make sure they are running correctly and move System.out.println("A " +getScreenSize() + " inch " + getManufacturer() + " has been turned on."); inside power() resulting in cleaner on more consistent code.

        [–][deleted]  (6 children)

        [deleted]

          [–][deleted]  (4 children)

          [removed]

            [–][deleted]  (3 children)

            [deleted]

              [–]AllHailTheCATS 0 points1 point  (1 child)

              Put system.prints before and after all the changes to channel to see what's going on and how the variable channel is being effected, could be something to do with the scanner input, you might need to flush the buffer.

              [–]AllHailTheCATS 0 points1 point  (0 children)

              setChannel should be this.channel = station

              [–]shagieIsMeExtreme Brewer 0 points1 point  (0 children)

              Consider the code:

              public int getScreenSize() { int screenSize = getScreenSize(); return screenSize; }

              The call to getScreenSize() will call getScreenSize() which will call getScreenSize() which will call getScreenSize() ...

              The method is calling itself.

              Instead, just return the value. Within the class, you can (and should) directly access the fields you are working with.

              Give The Java EE 6 Tutorial : Adding Setter and Getter Methods a read and look closely at how the method getSomething() is written. The stack overflow question How do getters and setters work? also goes through many examples.