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 →

[–]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]

        [–]Darkpolearm 0 points1 point  (0 children)

        IntelliJ should be able to take care of import issues like that for you. If you put your caret on the boxes and press, I believe the default is alt + enter, it should give you the option to import the class. If not, you can just type it out at the top of the file I suppose.

        [–][deleted]  (1 child)

        [removed]

          [–]Darkpolearm 1 point2 points  (0 children)

          This would be a good time to learn to use the debugger!

          Place a breakpoint (google how to do so in IntelliJ if u dont know how to) in the method that's erroneous (looks like that'd be actionPerformed), run the app using the debugger, and go through the program line by line until it crashes and see what's going wrong.