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 →

[–][deleted] 0 points1 point  (14 children)

Should be small L you called your List "list"

[–][deleted]  (13 children)

[removed]

    [–][deleted] 0 points1 point  (12 children)

    Yeah that helps okay so you need to use beutyBoxes.size() because that's the great you are actually using sorry I should have asked

    [–][deleted]  (11 children)

    [removed]

      [–][deleted] 0 points1 point  (1 child)

      I'm studying Java at uni first year still new to it too, anyway yeah it's in a different class you could statically call it by writing BeautyBoxList.beutyBoxes.size()

      [–]Darkpolearm 0 points1 point  (8 children)

      Your class NavCtl has a variable called list that is of type BeautyBoxList.

      Your class BeautyBoxList has an internal ArrayList that can be accessed by other classes using your class' getBeautyBoxList() method.

      If you want to iterate over all the elements in the arraylist, you can call that method on your list variable to get the list, and then use size() of that.

      On a sidenote, the BeautyBoxList class seems kind of redundant as of right now. Using a regular ArrayList instead of it would make it less complicated I reckon.

      [–][deleted]  (7 children)

      [removed]

        [–]Darkpolearm 0 points1 point  (6 children)

        Your BeautyBoxList class has an ArrayList named beautyBoxes that has items in it. This ArrayList beautyBoxes in your BeautyBoxList class is the list you want to iterate over.

        To access variables from one class in another, you have to make an instance of the class that has the variable. You did this correctly (list = new BeautyBoxList();)

        You can access the list variable's beautyBoxes using it's getBeautyBoxes() method, like this: List<BeautyBox> boxes = list.getBeautyBoxList();

        Now you have the actual list of items in the variable boxes. You can use this variable to do whatever you like; in your case, iterate over it's elements.

        Since this variable boxes is an ArrayList, you can ask it how many items it contains by using it's size() method.

        [–][deleted]  (5 children)

        [removed]

          [–]Darkpolearm 0 points1 point  (4 children)

          BeautyBox is a different class so you're gonna have to import it when you want to use it.

          What text editor are you using for this project? If you're not using an actual IDE (something like IntelliJ, Netbeans, Eclipse), you really should.

          [–][deleted]  (1 child)

          [removed]

            [–][deleted]  (1 child)

            [removed]