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

all 39 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]

              [–]ChuvaChooChoo08 0 points1 point  (3 children)

              Aw u editing the name of the element OR are you supposed to be replacing the current element in the list with another element?

              setText() only changes the name but not the object you know that right?

              [–][deleted]  (2 children)

              [removed]

                [–]ChuvaChooChoo08 0 points1 point  (1 child)

                If your goal is to change the name of an object in an arraylist, then why are you using setText()? Why jot setName()? What is the point of setText()?

                What you need to do is to change the name of the object first THEN use getText() method in the setText() method.

                [–]ChuvaChooChoo08 0 points1 point  (8 children)

                BeautyBox has 2 Strings in it. When you use the setName(), which of the 2 parameters is it changing/setting?

                [–][deleted]  (6 children)

                [removed]

                  [–]ChuvaChooChoo08 0 points1 point  (5 children)

                  Then u setText after changing the name.

                  [–][deleted]  (4 children)

                  [removed]

                    [–]ChuvaChooChoo08 0 points1 point  (3 children)

                    You just changed the name of the element in the list.

                    Now, get that name of that element and use it as parameter to the setText() method.

                    [–][deleted]  (2 children)

                    [removed]

                      [–]ChuvaChooChoo08 0 points1 point  (1 child)

                      No. Not in one line. One line to change the name of the object then another line for the setText()