#Cannot resolve method

1 messages · Page 1 of 1 (latest)

waxen geyser
#

Hi,

I'm getting this weird error where it can't access the set method (compilation error as well) but this makes no sense, look at the code:


public boolean set(K key, V val)
    {
        // Find the desired value
        int index = this.hash(key);
        Bucket<K, V> bucket = this.table[index];

        KeyValuePair<K, V> curr = bucket.head;

        // Search iteratively for the target element within the bucket
        while(curr != null)
        {
            // If the key is equal to the one we want to set
            if(curr.getKey().equals(key))
            {
                curr.setVal(val);
                return true;
            }
            curr = curr.getNext();
        }

        throw new NoSuchElementException("Key does not exist within the HashMap!");
    }```

And the function trying to access this method:

```java

private void updateAverageRating(int movieid, float rating)
    {
        // Retrieve the old average, if it is a null no average was set yet so simply assign 0
        RatingAverage avg = averageMovieRatings.get(movieid);

        float oldAverage = avg.getAverage();
        float newAverage = oldAverage + (rating / avg.getMovieCount());

        averageMovieRatings.set(movieid, newAverage);
    }```

set is public and defined within averageMovieRatings which is an instance of HashMap which contains the method. Why on earth is it not finding set?
olive ermineBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

V value) {
if (key == null || value == null) {
return false;
}
int index = getIndex(key);
Entry<K, V> entry = table[index];

    while (entry != null) {
        if (entry.getKey().equals(key)) {
            entry.setValue(value);
            return true;
        }
        entry = entry.getNext();
    }
    
    Entry<K, V> newEntry = new Entry<>(key, value);
    newEntry.setNext(table[index]);
    table[index] = newEntry;
    
    size++;
    return true;
}

The error message says "Cannot resolve method 'setNext(Entry<K,V>)'" but I can clearly see that the setNext method is being called on the newEntry object. What could be causing this issue?
devout niche
#

your type's dont match though

#

your placing a float and it wants a RatingAverage

waxen geyser
#

Good point but still doesn’t explain the issue with the method

devout niche
#

what issue ?

#

the .set() that your trying to use is not known on the hashmap so its saying compilation

waxen geyser
#

The set method is known though

#

It's literally defined in the class as a public method

lament wigeon
#

You’re calling set(int, float) instead of set(int, RatingAverage) , based on the types of your Map keys and values. So the error is that the method set does not exist with the signature you’re asking for

waxen geyser
#

Again it is not that I've corrected this look:


private void updateAverageRating(int movieid, float rating)
    {
        // Retrieve the old average, if it is a null no average was set yet so simply assign 0
        RatingAverage avg = averageMovieRatings.get(movieid);

        float oldAverage = avg.getAverage();
        float newAverage = oldAverage + (rating / avg.getMovieCount());

        avg.setAverage(newAverage);

        averageMovieRatings.set(movieid, avg);
    }```
olive ermineBOT
waxen geyser
#

I have the same issue, it says it can't find the symbol method. If it was related to the types Java would be complaining about the type of data passed into the method being wrong, not the method not existing

sharp acorn
#

Show the error after changing the set call

waxen geyser
sharp acorn
#

can you show also where averageMovieRatings is defined

#

nevermind, the method you are looking for is called put not set

waxen geyser
#

no it isn't

#

it's a custom hashmap written by me

#

this isn't the java.util one

#

mine is called set

waxen geyser
#

nevermind intellij decided to secretly import java.util hashmap even though it wasn't what i autocompleted and then hide the import statements