'Netbeans class' method not recognized

I'm having a fairly odd problem with Netbeans.

I'm trying to calculate the sum of an ArrayList, but I am not able to call the method public int sumOfHand() onto my this.hands variable.

I've restarted Netbeans numerous times, created new classes and tried to calculate the sum using the .reduce() method using streams, but none of it helped. Thanks for any suggestion!

import java.util.List;
import java.util.stream.Stream;
import java.util.ArrayList;
import java.util.Collections;

public class Hand implements Comparable<Hand>{
    public ArrayList<Card> hands;
    
    public Hand() {
        this.hands = new ArrayList<>();
    }
    
    public void add(Card card) {
        this.hands.add(card);
    }
    
    public void print() {
        this.hands.forEach(crd -> {System.out.println(crd);});
    }
    
    public void sort() {
        Collections.sort(this.hands, (crd1, crd2) -> crd1.compareTo(crd2));
    }
    
    @Override
    public int compareTo(Hand otherHand) {
       // sumOfHand() not recognized here, 'Cannot find symbol'
       return this.hands.sumOfHand() - otherHand.sumOfHand();
    }
               
    public int sumOfHand() {
        int sum = 0;
        for (Card tc : this.hands) {
            sum += tc.getValue();
        }
        return sum; 
    }
    
}


Solution 1:[1]

You can't call a int sumOfHand() of this.hands as hands is an ArrayList.class and int sumOfHand() is a method of Hand.class. To call this method you need to use this.sumOfHands() inside your Hand.class.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Serhii Zhura