I'm working on a code to calculate a final score.

Here below is my code:

``````public void calcFinalOCAS()
{
int calcFinalOCAS;
int sum = 0;
List<Integer> tmaMarks = new ArrayList<Integer>();
Collections.sort(tmaMarks);
int minMarks = Collections.min(tmaMarks);
if(minMarks < substitutionScore)
{
minMarks = substitutionScore;
}
for (int i = 0; i < tmaMarks.size(); i = i+1)
{
sum = sum + tmaMarks.get(i);
calcFinalOCAS = (sum)/4;
}
}``````

When I run it I get a semantic error: Exception: java.util.NoSuchElementException

Can someone would help me to know what that error means?:)

You didn't say which line the error is occurring on, but I am guessing that it's this one

``int minMarks = Collections.min(tmaMarks);``

because the Collections.min() method states that exception is thrown when it's invoked on an empty collection - which you are doing.

Regarding the rep comment about it possibly being the Collection.sort() call, no it is not, read the API docs - NoSuchElementException is not thrown by that method.
Sorting an empty collection is actually the easiest operation you could hope to implement :P

Thanks again Ezzaral,

I got that semantic error gone, but I'm stuck on another line :)

``````List<Integer> finalT = new ArrayList<Integer>(tmaMarks);
int minMarks = Collections.min(finalT);
this.getSubstitutionScore();
if(substitutionScore > minMarks)
{
minMarks = substitutionScore;
System.out.println(finalT);
}``````

The code works fine to get the minimum marks. But I want to replace the min marks by the substitutionScore and it is not working. I tried to use a swap method but got a semantic error

Never mind I got it:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.