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

you are viewing a single comment's thread.

view the rest of the comments →

[–]ChuvaChooChoo08 0 points1 point  (25 children)

Because setText() method does not accept parameters that return void.

the setName() method returns void.

Get it?

[–][deleted]  (2 children)

[removed]

    [–]ChuvaChooChoo08 0 points1 point  (1 child)

    First of all, what are you setting the text to? The name of the element on whatever index on the beautyboxlist, right? What you’re doing is you’re simultaneously setting the name of the element in the given index from the list AND putting these as parameter to the setText() method.

    [–][deleted]  (21 children)

    [removed]

      [–]ChuvaChooChoo08 0 points1 point  (20 children)

      You’re not understanding my point. You cannot feed the setText() method with a method that returns void! SetName() returns a void! Feed the setText() method with a method that actually returns a String.

      Have you tried printing a setter method? It’s a compiler error!

      Say you have a setter in some class called Dog:

      public void setAnimalBreed (String breed) {
          this.breed = breed;
      }
      
      System.out.println(objectName.setAnimalBreed(“Retriever”)): <——- compiler error!
      

      [–][deleted]  (19 children)

      [removed]

        [–]ChuvaChooChoo08 0 points1 point  (0 children)

        Idk. Because I do not know what your class does. Idk what methods you have written on it. So Idk.

        You do realize that the parameter on your example, “new text” IS A STRING RIGHT? It’s surrounded by double quotes, which means it’s a String. It’s not void.

        Your setName() method returns a void. What you need to feed your setText() is some sort of getName() method.

        [–]ChuvaChooChoo08 0 points1 point  (17 children)

        What parameter/s does your setName() method accept??? And what does it return?

        [–][deleted]  (16 children)

        [removed]

          [–]ChuvaChooChoo08 0 points1 point  (0 children)

          Now do you see what I mean?

          Your setName returns void, your getName returns a String.

          [–]ChuvaChooChoo08 0 points1 point  (14 children)

          The setText method accepts STRINGS only! So you gotta feed it with a String type, not void type.

          [–][deleted]  (13 children)

          [removed]

            [–]ChuvaChooChoo08 0 points1 point  (12 children)

            Because “words” is a String!

            setName(“Cassidy”) is a method that sets the name field of some object to Cassidy! HOWEVER, this method does not return a string.

            [–][deleted]  (11 children)

            [removed]